/*==============================================\
|  File name:   Muslims in Europe_replication.do|
|  DATE:		8/2024                          |            
|  LOG FILE:   immigrants_discriptives.log      |
|  AUTHOR:     Odelia Oshri                     |
\==============================================*/


use  "C:\Users\User\Downloads\ess1-10.dta", clear
capture log using "immigrants_discriptives.log", replace
/*Part 1: clean data*/
/*keep cntry essround polintr trstplt lrscale prtv* brncntr gndr agea domicil eduyrs emplrel emplno iscoco isco08 uemp3m ipadvnt vote prtyban */

* Recode gender (male=1)**
tab gndr
recode gndr 2=0 1=1
drop if gndr>1
tab gndr
label define gndr 0 "F" 1 "M", replace
label values gndr gndr
tab gndr
rename gndr Male

* Turn variable "essround" into "Year" 
gen year=.
replace year=2002 if essround==1
replace year=2004 if essround==2
replace year=2006 if essround==3
replace year=2008 if essround==4
replace year=2010 if essround==5
replace year=2012 if essround==6
replace year=2014 if essround==7
replace year=2016 if essround==8
replace year=2018 if essround==9
replace year=2020 if essround==10

* Kepp Western European Countries** /*we're left with 18 countries*/
keep if cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DE"|cntry=="DK"|cntry=="ES"|cntry=="FI"|cntry=="FR"|cntry=="GB"|cntry=="GR"|cntry=="IE"|cntry=="IT"|cntry=="LU"|cntry=="NL"|cntry=="NO"|cntry=="PT"|cntry=="SE"|cntry=="IS"

*generate cntryear variable
gen year_2dig = string(mod(year,100), "%02.0f")  
gen cntryear=cntry+year_2dig
* GENERATE NUMERICAL VARIABLE FOR COUNTRY 
egen country = group(cntry)              
label define country 1 "AT" 2 "BE" 3 "CH" 4 "DE" ///
5 "DK" 6 "ES" 7 "FI" 8 "FR" 9 "GB" 10 "GR" 11 "IE" ///
12 "IS" 13 "IT" 14 "LU" 15 "NL" 16 "NO" 17 "PT" 18 "SE" , replace
label values country country
* L-R SCALE
ta lrscale, mis
drop if lrscale>10
/*DISCROIMINATION (member of a group discriminated against in this country)*/
recode dscrgrp 1=1 2=0
ta dscrgrp
* CONTROLS *

* Population desity *
tab domicil, nol
drop if domicil>5
recode domicil 1=5 2=4 3=3 4=2 5=1 , gen(popdens)          
label define popdens 1 " Farm or home in countryside" ///
2 "Country village" 3 "Town or small city" ///
4 "Suburbs or outskirts of big city" 5  "A big city" , replace
label values popdens popdens 
label variable popdens "Population density"

* Education in yrs *
tab eduyrs, nol                      
drop if eduyrs>56

* Age *
tab agea
drop if agea>102
drop if agea<18
tab agea

*Age Squared* 
gen sqrage=agea*agea

/* Unemployment: (uemp3m) Have you ever been unemployed and seeking work
for a period of more than three months? */
tab uemp3m, nol
drop if uemp3m>2
recode uemp3m 2=0 1=1
rename uemp3m unemp3
tab unemp3 

* RELIGIOSITY 
tab rlgdgr
drop if rlgdgr> 10
rename rlgdgr religiousity 
tab religiousity 

**------------------------------------------------ 
** Creating a "Migration Status" variable: mstatus  
** ------------------------------------------------ **
** Natives: mstatus = 1                             **
** 1st generation migrants: mstatus = 2             **
** 2nd generation migrants: mstatus = 3             **

** we now generate a migration variable that encompasses all first and second generation migrants 
** we define as first generation migrants all individuals that were born in a different country of origin
** second generation migrants are all individuals that were born in the same country, BUT have at least one of the two parents born in a different country


drop if facntr>2|mocntr>2|brncntr>2

gen mstatus=.

replace mstatus=1 if brncntr==1  &    facntr==1 &   mocntr==1   /*respondent and paerents were born in the country of residence*/
replace mstatus=2 if brncntr==2                           /*a 1st gen migrant is NOT born in the host country (brncntr==2)*/
replace mstatus=3 if brncntr==1 & (facntr==2 | mocntr==2) /*a 2nd gen migrant is born in the host country (brncntr==2) BUT at least one parent is NOT born in the host country*/
label variable mstatus "based on birth country"
label define mstatus 1 "native" 2 "1st generation" 3 "2nd generation", replace
label values mstatus mstatus

/*cntry of origin*/
gen origin="."
replace origin=cntry if mstatus==1                      /*the origin of a native is the country of residence*/
replace origin=cntbrth if mstatus==2 & essround==1
replace origin=cntbrtha if mstatus==2 & (essround==2|essround==3)
replace origin=cntbrthb if mstatus==2 & (essround==4|essround==5)
replace origin=cntbrthc if mstatus==2 & (essround==6|essround==7|essround==8)
replace origin=cntbrthd if mstatus==2 & (essround==9|essround==10)  /*the origin of a first generation migrant is his/her country of birth*/

replace origin=fbrncnt if mstatus==3 & facntr==2 & (essround==2 |essround==3 )   /*the origin of a second generation migrant is the country of birth of the father, 
                                                                    if the father is a migrant, in ESS waves 2-7 (info is not available in ESS1)*/
replace origin=fbrncnta if mstatus==3 & facntr==2 & (essround==4|essround==5)
replace origin=fbrncntb if mstatus==3 & facntr==2 & (essround==6|essround==7|essround==8)
replace origin=fbrncntc if mstatus==3 & facntr==2 & (essround==9|essround==10)

												
replace origin=mbrncnt if mstatus==3 & origin=="." & (essround==2 |essround==3 )   /*the origin of a second generation migrant is the country of birth of the mother 
if the origin is still missing (i.e. the father is not a migrant),in ESS waves 2-7 (as this info is not available in ESS1)*/  
replace origin=mbrncnta if mstatus==3 & origin=="." & (essround==4 |essround==5 )
replace origin=mbrncntb if mstatus==3 & origin=="." & (essround==6|essround==7|essround==8)	
replace origin=mbrncntc if mstatus==3 & origin=="." & (essround==9|essround==10)														
											
ta origin if mstatus==2|mstatus==3
gen west=0 
replace west=1 if origin=="AT"| origin=="AU" |origin=="BE" |origin=="BG"| origin=="CA" |origin=="CX" |origin=="CY"|origin== "03" |origin=="CH" |origin=="DE" |origin=="DK"| origin=="DO"| origin=="EE" |origin=="FO"| origin=="ES"| origin=="FI"| origin=="FR" |origin=="GB" |origin=="GL"|origin=="GR" |origin=="JP"|origin== "HU"|origin== "IE"| origin=="IL" |origin=="IS"|origin== "IT"| origin=="LT" |origin=="LU" |origin=="LV" |origin=="NL" |origin=="NZ"| origin=="NO" |origin=="PL"| origin=="PH" |origin=="PT" |origin=="RO" |origin=="SE" |origin=="SI" |origin=="SK" |origin=="US"

gen imgstatus=.
replace imgstatus=1 if  mstatus==1 /*native*/
replace imgstatus=2 if west==1 & mstatus==2 /*1st gen western*/
replace imgstatus=3 if west==1 & mstatus==3 /*2nd gen western*/
replace imgstatus=4 if west==0 & mstatus==2 /* 1st gen non western*/
replace imgstatus=5 if west==0 & mstatus==3 /*2nd gen non western*/
label define imgstatus 1 "Native" 2 "1st gen Western" 3 "2nd gen Western" 4 "1st gen non-Western" 5 "2nd gen non-Western"
label value imgstatus imgstatus
/*DUMMY FOR 1ST AND 2ND GEN NON WESTERN*/
gen nonwest=0
replace nonwest=1 if imgstatus==5
replace nonwest=1 if imgstatus==4


/*Religion*/
ta rlgdnm if (mstatus==2 |mstatus==3) /*Islam category 6 3969 respondents, 17% of immigrants*/
/*MUSLIM IMMIGRANTS*/
ta rlgdnm if west==0 & (mstatus==2 |mstatus==3)

gen muslim=0
replace muslim=1 if rlgdnm==6 
label define muslim 0 "non muslim" 1 "muslim", replace
label value muslim muslim
gen muslimcat=.
replace muslimcat=0 if mstatus==1 /*Non Muslim native*/
replace muslimcat=1 if mstatus==1 &rlgdnm==6 /*Native Muslim (probably 3rd gen)*/
replace muslimcat=2 if mstatus==2 &rlgdnm==6 /*1st gen Muslim*/
replace muslimcat=3 if mstatus==3 &rlgdnm==6 /*2nd gen Muslim*/
label define muslimcat 0 "Non Muslim native" 1 "3rd gen Muslim" 2 "1st gen Muslim" 3 "2nd gen Muslim", replace
label values muslimcat muslimcat

edit cntryear muslim 
sort muslim
separate muslim, by(cntry) veryshortlabel
graph hbar  muslim1-muslim18  , scheme(plottig)   ///
over (cntryear, sort(muslim) label(labsize(*.34)))  ysize(9) xsize(7) title ("% muslims ") nofill legend(off)  
/*APPENDIX D*/
graph hbar muslim,  scheme(plotplain)   ///
over (cntry, sort(muslim)  label(labsize(*.54)))   ysize(9) xsize(7) title ("% of Muslims") nofill legend(off)  


*the biggest non-Western minority group in each country*/
gen bigmnrty=0
replace bigmnrty=1 if cntry=="AT" & origin=="TR" 
replace bigmnrty=1 if cntry=="BE" & (origin=="TR" | origin=="MA")
replace bigmnrty=1 if cntry=="CH" & (origin=="TR" | origin=="BA"| origin=="XK")
replace bigmnrty=1 if cntry=="DE" & origin=="TR" 
replace bigmnrty=1 if cntry=="DK" & origin=="TR" 
replace bigmnrty=1 if cntry=="ES" & origin=="MA" 
replace bigmnrty=1 if cntry=="FI" & (origin=="SO" | origin=="TK"| origin=="SO")
replace bigmnrty=1 if cntry=="FR" & (origin=="DZ" | origin=="MA"| origin=="TN")
replace bigmnrty=1 if cntry=="GB" & (origin=="IN" | origin=="PK"| origin=="TN")
replace bigmnrty=1 if cntry=="IE" & (origin=="IN" | origin=="NG")
replace bigmnrty=1 if cntry=="IT" &rlgdnm==6 
replace bigmnrty=1 if cntry=="NL" & (origin=="ID" | origin=="TR")
replace bigmnrty=1 if cntry=="NO" & (origin=="IQ" | origin=="PK"| origin=="IR")
replace bigmnrty=1 if cntry=="SE" & rlgdnm==6 
ta bigmnrty
label define bigmnrty 0 "non muslim" 1 "muslim immigrant community"
label value bigmnrty bigmnrty


*trust in politicians
drop if trstplt >10

* 1-DIGIT ISCO OCCUPATION , 
gen  occupation=.   
replace occupation=1 if (iscoco<=1999&iscoco>=1000) | (isco08<=1999&isco08>=1000)
replace occupation=2 if (iscoco<=2999&iscoco>=2000) | (isco08<=2999&isco08>=2000)
replace occupation=3 if (iscoco<=3999&iscoco>=3000) | (isco08<=3999&isco08>=3000)
replace occupation=4 if (iscoco<=4999&iscoco>=4000) | (isco08<=4999&isco08>=4000)
replace occupation=5 if (iscoco<=5999&iscoco>=5000) | (isco08<=5999&isco08>=5000)
replace occupation=6 if (iscoco<=6999&iscoco>=6000) | (isco08<=6999&isco08>=6000)
replace occupation=7 if (iscoco<=7999&iscoco>=7000) | (isco08<=7999&isco08>=7000)
replace occupation=8 if (iscoco<=8999&iscoco>=8000) | (isco08<=8999&isco08>=8000)
replace occupation=9 if (iscoco<=9999&iscoco>=9000) | (isco08<=9999&isco08>=9000)
replace occupation=0 if iscoco==100 |  isco08<1000
label define occupation 1 " Legislators, senior officials and managers" ///
2 "Professionals" 3 " Technicians and associate professionals" 4 "Clerks " ///
5 "Service workers and shop and market sales workers" 6 "Skilled agricultural and fishery workers" ///
7 "Craft and related trades workers" 8 " Plant and machine operators and assemblers" ///
9 "Elementary occupations" 0 "Armed forces", replace
label values occupation occupation 

/* Communication and manual dexterity indicators:
   values are taken from D'Amuri et al. (2014). The authors lump the O*Net
   values for the intensity of 78 tasks for the 339 occupations identified by the 
   Standard Occupation Classification (SOC) into 5 broader categories: 
   communication, mental, complex, manual and routine. They then convert each 
   of the five broad skill 'indicators' into a percentile by sector, describing 
   the particular skill intensity of the occupation compared to others. Once 
   each of the 339 occupations is assigned a percentile score D'Amuri et al. 
   lump occupations to twenty one occupational categories according to the 
   ISCO classification of occupations. The percentile score of each such category 
   is a weighted average of the scores of the relevant original occupations where 
   the weights are the proportion of the US population in each of the 339 ISCO 
   occupations according to the 2000 US Census. Lastly, we collapse 
   D'Amuri et al.s twenty-one occupational categories into ten sectors using
   a broader ISCO sector classification whereby the skill percentile score of 
   each sector is the simple average of the occupational categories that make up
   the sector.*/
gen communication=.
replace communication=85.45 if occupation==1
replace communication=69.46 if occupation==2
replace communication=67.42 if occupation==3
replace communication=70.18 if occupation==4
replace communication=64.46 if occupation==5
replace communication=18.10 if occupation==7
replace communication=21.11 if occupation==8
replace communication=29.86 if occupation==9

gen manual=.
replace manual=21.75 if occupation==1
replace manual=38.14 if occupation==2
replace manual=37.83 if occupation==3
replace manual=29.20 if occupation==4
replace manual=38.61 if occupation==5
replace manual=75.32 if occupation==7
replace manual=78.23 if occupation==8
replace manual=71.19 if occupation==9

generate man_ord=.
replace man_ord=1 if occupation==1
replace man_ord=2 if occupation==4
replace man_ord=3 if occupation==3
replace man_ord=4 if occupation==2
replace man_ord=5 if occupation==5
replace man_ord=6 if occupation==9
replace man_ord=7 if occupation==7
replace man_ord=8 if occupation==8
label define man_ord 1 " Legislators, senior officials and managers" ///
2 "Clerks "  3 " Technicians and associate professionals" 4 "Professionals" ///
5 "Service workers and shop and market sales workers" 6 "Elementary occupations"  ///
7 "Craft and related trades workers" 8 " Plant and machine operators and assemblers" ///
, replace
label values man_ord  man_ord


gen routine=.
replace routine=48.75 if occupation==1
replace routine=50.40 if occupation==2
replace routine=49.35 if occupation==3
replace routine=26.34 if occupation==4
replace routine=33.01 if occupation==5
replace routine=73.68 if occupation==7
replace routine=77.43 if occupation==8
replace routine=57.30 if occupation==9

gen comm=communication/100
gen man=manual/100


/* 2. Define party families */
/*key for party coding, 
tens digit of party families is as the following:
   Communist	   1
   Left			   2
   Green		   3
   Liberal		   4
   Religious/CD	   5
   Aggrarian	   6
   Conservative	   7
   Radical Right   8
   Ethnic/Regional 9  
*/
/*Four sources of party family*/
gen prtyfam_lmn=.
gen prtyfam_glm=.
gen prtyfam_gn=.
gen prtyfam_parlgov=.
gen prtyfam_ours=.

**Austria**
replace prtyfam_lmn=21 if prtvtat==1 /*spo*/
replace prtyfam_lmn=52 if prtvtat==2 /*ovp*/
replace prtyfam_lmn=82 if prtvtat==3 /*fpo*/
replace prtyfam_lmn=31 if prtvtat==4 /*grn*/
replace prtyfam_lmn=21 if prtvtaat==1
replace prtyfam_lmn=52 if prtvtaat==2
replace prtyfam_lmn=82 if prtvtaat==3
replace prtyfam_lmn=86 if prtvtaat==4
replace prtyfam_lmn=31 if prtvtaat==5 
replace prtyfam_lmn=21 if prtvtbat==1 
replace prtyfam_lmn=52 if prtvtbat==2 
replace prtyfam_lmn=82 if prtvtbat==3 
replace prtyfam_lmn=86 if prtvtbat==4 
replace prtyfam_lmn=31 if prtvtbat==5 
replace prtyfam_lmn=41 if prtvtbat==7 
replace prtyfam_ours=41 if prtvtbat==9
replace prtyfam_lmn=21 if prtvtcat==1 
replace prtyfam_lmn=52 if prtvtcat==2 
replace prtyfam_lmn=82 if prtvtcat==3 
replace prtyfam_lmn=31 if prtvtcat==5 
replace prtyfam_lmn=41 if prtvtcat==7 

**Belguim**
replace prtyfam_lmn=51 if prtvtbe==2 /*cvp*/
replace prtyfam_lmn=21 if prtvtbe==3 /*sp*/
replace prtyfam_lmn=41 if prtvtbe==5 /*vld*/
replace prtyfam_lmn=91 if prtvtbe==6 /*vu-id*/
replace prtyfam_lmn=81 if prtvtbe==8 /*vlaams blok*/
replace prtyfam_lmn=31 if prtvtbe==11 /*ecolo*/
replace prtyfam_lmn=51 if prtvtbe==12 /*psc*/
replace prtyfam_lmn=41 if prtvtbe==13
replace prtyfam_lmn=21 if prtvtbe==14 /*ps*/
replace prtyfam_lmn=51 if prtvtabe==2 /*CD&V*/
replace prtyfam_lmn=91 if prtvtabe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtabe==5/*SP.A-Spirit */
replace prtyfam_lmn=82 if prtvtabe==7 /*Vlaams Blok*/
replace prtyfam_lmn=41 if prtvtabe==8
replace prtyfam_lmn=51 if prtvtabe==9
replace prtyfam_lmn=31 if prtvtabe==10
replace prtyfam_lmn=81 if prtvtabe==11 /*Front National */
replace prtyfam_lmn=41 if prtvtabe==12
replace prtyfam_lmn=21 if prtvtabe==13 /*ps*/
replace prtyfam_lmn=31 if prtvtbbe==1
replace prtyfam_lmn=51 if prtvtbbe==2
replace prtyfam_lmn=41 if prtvtbbe==4
replace prtyfam_lmn=21 if prtvtbbe==5 /*SP.A-Spirit */
replace prtyfam_lmn=81 if prtvtbbe==7
replace prtyfam_lmn=41 if prtvtbbe==8
replace prtyfam_lmn=51 if prtvtbbe==9
replace prtyfam_lmn=31 if prtvtbbe==10
replace prtyfam_lmn=81 if prtvtbbe==11
replace prtyfam_lmn=41 if prtvtbbe==12
replace prtyfam_lmn=21 if prtvtbbe==13/*ps*/
replace prtyfam_lmn=31 if prtvtcbe==1
replace prtyfam_lmn=51 if prtvtcbe==2
replace prtyfam_lmn=91 if prtvtcbe==3 /*N-VA*/
replace prtyfam_lmn=41 if prtvtcbe==4
replace prtyfam_lmn=21 if prtvtcbe==5
replace prtyfam_lmn=41 if prtvtcbe==8
replace prtyfam_lmn=51 if prtvtcbe==9
replace prtyfam_lmn=31 if prtvtcbe==10
replace prtyfam_lmn=81 if prtvtcbe==11
replace prtyfam_lmn=41 if prtvtcbe==12
replace prtyfam_lmn=21 if prtvtcbe==13/*ps*/
replace prtyfam_lmn=82 if prtvtcbe==15
replace prtyfam_lmn=31 if prtvtdbe==1 /*Groen!*/
replace prtyfam_lmn=51 if prtvtdbe==2 /*CD&V */
replace prtyfam_lmn=91 if prtvtdbe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtdbe==5 /*SP.A*/
replace prtyfam_lmn=22 if prtvtdbe==6 /*PVDA*/
replace prtyfam_lmn=82 if prtvtdbe==7 /*Vlaams Blok*/
replace prtyfam_lmn=41 if prtvtdbe==8 /*open vld*/
replace prtyfam_lmn=51 if prtvtdbe==9 /*cdh*/
replace prtyfam_lmn=31 if prtvtdbe==10 /*ecolo*/
replace prtyfam_lmn=41 if prtvtdbe==12 /*mr*/
replace prtyfam_lmn=21 if prtvtdbe==13/*ps*/
replace prtyfam_lmn=82 if prtvtdbe==15
replace prtyfam_lmn=91 if prtvtdbe==16
replace prtyfam_lmn=31 if prtvtebe==1 /*Groen!*/
replace prtyfam_lmn=51 if prtvtebe==2 /*CD&V */
replace prtyfam_lmn=91 if prtvtebe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtebe==4 /*SP.A*/
replace prtyfam_lmn=22 if prtvtebe==5 /*PVDA*/
replace prtyfam_lmn=82 if prtvtebe==6 /*Vlaams Belang*/
replace prtyfam_lmn=41 if prtvtebe==7 /*open vld*/
replace prtyfam_lmn=51 if prtvtebe==8 /*cdh*/
replace prtyfam_lmn=31 if prtvtebe==9 /*ecolo*/
replace prtyfam_lmn=41 if prtvtebe==10 /*mr*/
replace prtyfam_lmn=21 if prtvtebe==11/*ps*/

**Denmark**
replace prtyfam_lmn=21 if prtvtdk==1/*Socialdemokratiet*/
replace prtyfam_lmn=41 if prtvtdk==2
replace prtyfam_lmn=71 if prtvtdk==3
replace prtyfam_lmn=22 if prtvtdk==5/*Socialistisk Folkeparti, clasified as radical left in ches */
replace prtyfam_lmn=86 if prtvtdk==6
replace prtyfam_lmn=51 if prtvtdk==7
replace prtyfam_lmn=41 if prtvtdk==8
replace prtyfam_ours=11 if prtvtdk==10
replace prtyfam_lmn=21 if prtvtadk==1
replace prtyfam_lmn=41 if prtvtadk==2
replace prtyfam_lmn=71 if prtvtadk==3
replace prtyfam_lmn=22 if prtvtadk==5
replace prtyfam_lmn=86 if prtvtadk==6
replace prtyfam_lmn=41 if prtvtadk==8
replace prtyfam_ours=11 if prtvtadk==10
replace prtyfam_lmn=21 if prtvtbdk==1
replace prtyfam_lmn=41 if prtvtbdk==2
replace prtyfam_lmn=71 if prtvtbdk==3
replace prtyfam_lmn=22 if prtvtbdk==4
replace prtyfam_lmn=86 if prtvtbdk==5
replace prtyfam_lmn=41 if prtvtbdk==7
replace prtyfam_lmn=41 if prtvtbdk==8
replace prtyfam_lmn=11 if prtvtbdk==9
replace prtyfam_lmn=21 if prtvtcdk==1
replace prtyfam_lmn=41 if prtvtcdk==2
replace prtyfam_lmn=71 if prtvtcdk==3
replace prtyfam_lmn=22 if prtvtcdk==4
replace prtyfam_lmn=86 if prtvtcdk==5
replace prtyfam_lmn=41 if prtvtcdk==7
replace prtyfam_lmn=41 if prtvtcdk==8
replace prtyfam_lmn=11 if prtvtcdk==9
replace prtyfam_lmn=21 if prtvtddk==1 /*l:sd*/
replace prtyfam_lmn=41 if prtvtddk==2
replace prtyfam_lmn=71 if prtvtddk==3
replace prtyfam_lmn=22 if prtvtddk==4 /*rl:sf*/
replace prtyfam_lmn=86 if prtvtddk==5 /*rr:df*/
replace prtyfam_lmn=41 if prtvtddk==7
replace prtyfam_lmn=41 if prtvtddk==8
replace prtyfam_lmn=31 if prtvtddk==9 /*grn:Alternative*/

**Finland**
replace prtyfam_lmn=71 if prtvtfi==1
replace prtyfam_lmn=91 if prtvtfi==2
replace prtyfam_lmn=61 if prtvtfi==4
replace prtyfam_lmn=86 if prtvtfi==5
replace prtyfam_lmn=51 if prtvtfi==6
replace prtyfam_lmn=31 if prtvtfi==8
replace prtyfam_lmn=21 if prtvtfi==9/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtfi==10
replace prtyfam_lmn=71 if prtvtafi==1
replace prtyfam_lmn=91 if prtvtafi==2
replace prtyfam_lmn=61 if prtvtafi==4
replace prtyfam_lmn=86 if prtvtafi==5
replace prtyfam_lmn=51 if prtvtafi==6
replace prtyfam_lmn=31 if prtvtafi==7
replace prtyfam_lmn=21 if prtvtafi==8
replace prtyfam_lmn=11 if prtvtafi==9
replace prtyfam_lmn=71 if prtvtbfi==1
replace prtyfam_lmn=91 if prtvtbfi==2
replace prtyfam_lmn=61 if prtvtbfi==4
replace prtyfam_lmn=86 if prtvtbfi==5
replace prtyfam_lmn=51 if prtvtbfi==6
replace prtyfam_lmn=31 if prtvtbfi==13
replace prtyfam_lmn=21 if prtvtbfi==14/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtbfi==15
replace prtyfam_lmn=71 if prtvtcfi==1
replace prtyfam_lmn=91 if prtvtcfi==2
replace prtyfam_lmn=61 if prtvtcfi==3
replace prtyfam_lmn=86 if prtvtcfi==4
replace prtyfam_ours=51 if prtvtcfi==5
replace prtyfam_lmn=31 if prtvtcfi==12
replace prtyfam_lmn=21 if prtvtcfi==13/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtcfi==14
replace prtyfam_lmn=71 if prtvtdfi==1
replace prtyfam_lmn=91 if prtvtdfi==2
replace prtyfam_lmn=61 if prtvtdfi==3
replace prtyfam_lmn=86 if prtvtdfi==4
replace prtyfam_lmn=51 if prtvtdfi==5
replace prtyfam_ours=31 if prtvtdfi==10
replace prtyfam_ours=21 if prtvtdfi==11/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtdfi==12
replace prtyfam_lmn=71 if prtvtefi==1
replace prtyfam_lmn=91 if prtvtefi==2
replace prtyfam_lmn=61 if prtvtefi==3
replace prtyfam_lmn=86 if prtvtefi==5 /*true finns*/
replace prtyfam_lmn=51 if prtvtefi==7
replace prtyfam_ours=31 if prtvtefi==16
replace prtyfam_ours=21 if prtvtefi==17/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtefi==18

**Germany**
replace prtyfam_lmn=21 if prtvde2==1 /*spd*/
replace prtyfam_lmn=51 if prtvde2==2 /*cdu*/
replace prtyfam_lmn=31 if prtvde2==3 /*grn*/
replace prtyfam_lmn=41 if prtvde2==4 /*fdp*/
replace prtyfam_lmn=11 if prtvde2==5 /*pds*/
replace prtyfam_lmn=21 if prtvade2==1
replace prtyfam_lmn=51 if prtvade2==2
replace prtyfam_lmn=31 if prtvade2==3
replace prtyfam_lmn=41 if prtvade2==4
replace prtyfam_lmn=11 if prtvade2==5
replace prtyfam_lmn=21 if prtvbde2==1
replace prtyfam_lmn=51 if prtvbde2==2
replace prtyfam_lmn=31 if prtvbde2==3
replace prtyfam_lmn=41 if prtvbde2==4
replace prtyfam_lmn=11 if prtvbde2==5
replace prtyfam_lmn=21 if prtvcde2==1
replace prtyfam_lmn=51 if prtvcde2==2
replace prtyfam_lmn=31 if prtvcde2==3
replace prtyfam_lmn=41 if prtvcde2==4
replace prtyfam_lmn=11 if prtvcde2==5
replace prtyfam_lmn=21 if prtvdde2==1
replace prtyfam_lmn=51 if prtvdde2==2
replace prtyfam_lmn=31 if prtvdde2==3
replace prtyfam_lmn=41 if prtvdde2==4
replace prtyfam_lmn=11 if prtvdde2==5
replace prtyfam_lmn=51 if prtvede2==1
replace prtyfam_lmn=21 if prtvede2==2
replace prtyfam_lmn=11 if prtvede2==3
replace prtyfam_lmn=31 if prtvede2==4
replace prtyfam_lmn=51 if prtvfde2==1
replace prtyfam_lmn=21 if prtvfde2==2
replace prtyfam_lmn=11 if prtvfde2==3
replace prtyfam_lmn=41 if prtvfde2==4
replace prtyfam_lmn=11 if prtvfde2==5
replace prtyfam_lmn=86 if prtvfde2==6

**Greece** 
replace prtyfam_lmn=21 if prtvtgr==1/*pasok*/
replace prtyfam_lmn=71 if prtvtgr==2
replace prtyfam_lmn=11 if prtvtgr==3
replace prtyfam_lmn=11 if prtvtgr==4
replace prtyfam_lmn=21 if prtvtagr==1
replace prtyfam_lmn=71 if prtvtagr==2
replace prtyfam_lmn=11 if prtvtagr==3
replace prtyfam_lmn=11 if prtvtagr==4
replace prtyfam_lmn=21 if prtvtbgr==1
replace prtyfam_lmn=71 if prtvtbgr==2
replace prtyfam_lmn=11 if prtvtbgr==3
replace prtyfam_lmn=11 if prtvtbgr==4
replace prtyfam_lmn=81 if prtvtbgr==5
replace prtyfam_lmn=21 if prtvtcgr==1
replace prtyfam_lmn=71 if prtvtcgr==2
replace prtyfam_lmn=11 if prtvtcgr==3
replace prtyfam_lmn=81 if prtvtcgr==4
replace prtyfam_lmn=11 if prtvtcgr==5
replace prtyfam_lmn=71 if prtvtdgr==1 /*nd**/
replace prtyfam_lmn=11 if prtvtdgr==2 /*syriza*/
replace prtyfam_lmn=21 if prtvtdgr==3 /*pasok*/
replace prtyfam_lmn=11 if prtvtdgr==4 /*kke*/
replace prtyfam_lmn=81 if prtvtdgr==5 /*el*/
replace prtyfam_lmn=11 if prtvtdgr==6 /*mr25*/

**Iceland**
replace prtyfam_lmn=86 if prtvtis==1
replace prtyfam_lmn=81 if prtvtis==2
replace prtyfam_lmn=21 if prtvtis==4/*Social Democratic Alliance*/
replace prtyfam_lmn=71 if prtvtis==5
replace prtyfam_lmn=11 if prtvtis==7
replace prtyfam_lmn=21 if prtvtais==1/*Social Democratic Alliance*/
replace prtyfam_lmn=71 if prtvtais==3
replace prtyfam_lmn=11 if prtvtais==4
replace prtyfam_lmn=41 if prtvtbis==1
replace prtyfam_lmn=86 if prtvtbis==2
replace prtyfam_lmn=71 if prtvtbis==3
replace prtyfam_lmn=21 if prtvtbis==8
replace prtyfam_lmn=11 if prtvtbis==10
replace prtyfam_lmn=41 if prtvtbis==11
replace prtyfam_ours=41 if prtvtbis==12
replace prtyfam_lmn=71 if prtvtcis==1
replace prtyfam_lmn=86 if prtvtcis==2
replace prtyfam_lmn=11 if prtvtcis==3
replace prtyfam_lmn=21 if prtvtcis==4
replace prtyfam_lmn=41 if prtvtcis==6
replace prtyfam_lmn=41 if prtvtcis==7
replace prtyfam_ours=61 if prtvtcis==8
replace prtyfam_ours=81 if prtvtcis==13 /*peoples party - claisfied as prrps by the PopuList*/
replace prtyfam_lmn=81 if prtvtdis==4 /*peoples party*/
replace prtyfam_lmn=86 if prtvtdis==5 /*progress party*/
replace prtyfam_lmn=61 if prtvtdis==6
replace prtyfam_lmn=41 if prtvtdis==7
replace prtyfam_lmn=21 if prtvtdis==8
replace prtyfam_lmn=71 if prtvtdis==9
replace prtyfam_ours=41 if prtvtdis==10
replace prtyfam_ours=11 if prtvtdis==11 

**Ireland**
replace prtyfam_lmn=41     if prtvtie==1/* Fianna Fáil */
replace prtyfam_lmn=51     if prtvtie==2
replace prtyfam_lmn=21     if prtvtie==3/*Labour*/
replace prtyfam_lmn=91     if prtvtie==4
replace prtyfam_lmn=31     if prtvtie==5
replace prtyfam_lmn=91     if prtvtie==6
replace prtyfam_lmn=41     if prtvtaie==1
replace prtyfam_lmn=51     if prtvtaie==2
replace prtyfam_lmn=21     if prtvtaie==5
replace prtyfam_ours=22    if prtvtaie==6 /*people before profit*/
replace prtyfam_lmn=91     if prtvtaie==7
replace prtyfam_parlgov=12 if prtvtaie==8
*replace prtyfam_ours=12    if prtvtaie==9
replace prtyfam_ours=22    if prtvtbie==1 /*people before profit*/
replace prtyfam_lmn=41     if prtvtbie==2
replace prtyfam_lmn=51     if prtvtbie==3
replace prtyfam_ours=31    if prtvtbie==4
replace prtyfam_lmn=31     if prtvtbie==5
replace prtyfam_ours=21    if prtvtbie==6 /*labour*/
replace prtyfam_lmn=91     if prtvtbie==7
replace prtyfam_ours=21    if prtvtbie==8 /*social democrats*/
replace prtyfam_ours=22    if prtvtcie==1 /*people before profit*/
replace prtyfam_lmn=41     if prtvtcie==2
replace prtyfam_lmn=51     if prtvtcie==3
replace prtyfam_ours=31    if prtvtcie==4
replace prtyfam_lmn=31     if prtvtcie==5
replace prtyfam_ours=21    if prtvtcie==6 /*labour*/
replace prtyfam_lmn=91     if prtvtcie==7
replace prtyfam_ours=21    if prtvtcie==8 /*social democrats*/
replace prtyfam_ours=41    if prtvtdie==1 
replace prtyfam_lmn=51     if prtvtdie==2
replace prtyfam_lmn=21     if prtvtdie==3 /*labour*/
replace prtyfam_ours=91    if prtvtdie==4
replace prtyfam_lmn=31     if prtvtdie==5
replace prtyfam_ours=31    if prtvtdie==6 
replace prtyfam_lmn=21     if prtvtdie==7
replace prtyfam_ours=22    if prtvtdie==8 /*social democrats*/

**Italy**
replace prtyfam_parlgov=21 if prtvtit==1/*democratici di Sinistra*/
replace prtyfam_parlgov=41 if prtvtit==2
replace prtyfam_lmn=11     if prtvtit==3
replace prtyfam_parlgov=31 if prtvtit==4
replace prtyfam_lmn=11     if prtvtit==7
replace prtyfam_lmn=71     if prtvtit==8
replace prtyfam_lmn=81     if prtvtit==9
replace prtyfam_lmn=52     if prtvtit==10
replace prtyfam_glm=83     if prtvtit==11
replace prtyfam_parlgov=21 if prtvtit==12 /*Nuovo PSI */
replace prtyfam_parlgov=21 if prtvtait==1
replace prtyfam_parlgov=41 if prtvtait==2
replace prtyfam_lmn=11     if prtvtait==3
replace prtyfam_parlgov=31 if prtvtait==4
replace prtyfam_lmn=92     if prtvtait==6
replace prtyfam_lmn=11     if prtvtait==7
replace prtyfam_lmn=71     if prtvtait==8
replace prtyfam_lmn=81     if prtvtait==9
replace prtyfam_lmn=52     if prtvtait==10
replace prtyfam_glm=83     if prtvtait==11
replace prtyfam_parlgov=21 if prtvtait==12
replace prtyfam_parlgov=21 if prtvtbit==1
replace prtyfam_parlgov=12 if prtvtbit==2
*replace prtyfam_lmn=11     if prtvtbit==3
replace prtyfam_parlgov=31 if prtvtbit==4
replace prtyfam_parlgov=41 if prtvtbit==5
replace prtyfam_lmn=52     if prtvtbit==6
replace prtyfam_lmn=42     if prtvtbit==8
replace prtyfam_lmn=81     if prtvtbit==9
replace prtyfam_ours=71    if prtvtbit==10
replace prtyfam_parlgov=21 if prtvtcit==1 /*pd*/
replace prtyfam_parlgov=41 if prtvtcit==2
replace prtyfam_parlgov=31 if prtvtcit==7
replace prtyfam_parlgov=71 if prtvtcit==8 /* Forza Italia */
replace prtyfam_lmn=81     if prtvtcit==9 /*lega nord*/
replace prtyfam_ours=71    if prtvtcit==10
replace prtyfam_parlgov=21 if prtvtdit==1 /*pd*/
replace prtyfam_parlgov=41 if prtvtdit==2
replace prtyfam_parlgov=31 if prtvtdit==3
replace prtyfam_parlgov=71 if prtvtdit==4 /* Forza Italia */
replace prtyfam_lmn=71    if prtvtdit==5 /*Fratelli*/
replace prtyfam_ours=41    if prtvtdit==7
replace prtyfam_ours=91    if prtvtdit==14

**Netherlands**
replace prtyfam_lmn=51     if prtvtnl==1
replace prtyfam_lmn=21     if prtvtnl==2/*labour*/
replace prtyfam_lmn=41     if prtvtnl==3
replace prtyfam_parlgov=81 if prtvtnl==4
replace prtyfam_lmn=41     if prtvtnl==5
replace prtyfam_lmn=22     if prtvtnl==6 /*green left*/
replace prtyfam_parlgov=52 if prtvtnl==7
replace prtyfam_parlgov=81 if prtvtnl==8
replace prtyfam_ours=81    if prtvtnl==9
replace prtyfam_lmn=51     if prtvtanl==1
replace prtyfam_lmn=21     if prtvtanl==2 /*labour*/
replace prtyfam_lmn=41     if prtvtanl==3
replace prtyfam_parlgov=81 if prtvtanl==4
replace prtyfam_lmn=41     if prtvtanl==5
replace prtyfam_lmn=31     if prtvtanl==6
replace prtyfam_lmn=22     if prtvtanl==7 /*green left*/
replace prtyfam_parlgov=52 if prtvtanl==8
replace prtyfam_ours=51    if prtvtanl==10
replace prtyfam_lmn=51     if prtvtbnl==1
replace prtyfam_lmn=21     if prtvtbnl==2
replace prtyfam_lmn=41     if prtvtbnl==3
replace prtyfam_parlgov=81 if prtvtbnl==4
replace prtyfam_lmn=41     if prtvtbnl==5
replace prtyfam_lmn=31     if prtvtbnl==6
replace prtyfam_lmn=22     if prtvtbnl==7
replace prtyfam_parlgov=52 if prtvtbnl==8
replace prtyfam_ours=51    if prtvtbnl==10
replace prtyfam_lmn=51     if prtvtcnl==1
replace prtyfam_lmn=21     if prtvtcnl==2
replace prtyfam_lmn=41     if prtvtcnl==3
replace prtyfam_lmn=41     if prtvtcnl==5
replace prtyfam_lmn=31     if prtvtcnl==6
replace prtyfam_lmn=22     if prtvtcnl==7 /*socialist party*/
replace prtyfam_parlgov=52 if prtvtcnl==8
replace prtyfam_ours=51    if prtvtcnl==10
replace prtyfam_lmn=41     if prtvtdnl==1
replace prtyfam_lmn=21     if prtvtdnl==2
replace prtyfam_parlgov=86 if prtvtdnl==3
replace prtyfam_lmn=22     if prtvtdnl==5 /*socialist party*/
replace prtyfam_lmn=41     if prtvtdnl==6
replace prtyfam_lmn=31     if prtvtdnl==7
replace prtyfam_parlgov=52 if prtvtdnl==8
replace prtyfam_lmn=41     if prtvtenl==1
replace prtyfam_lmn=21     if prtvtenl==2
replace prtyfam_parlgov=86 if prtvtenl==3
replace prtyfam_lmn=51     if prtvtenl==4
replace prtyfam_lmn=22     if prtvtenl==5
replace prtyfam_lmn=41     if prtvtenl==6
replace prtyfam_lmn=31     if prtvtenl==7
replace prtyfam_parlgov=52 if prtvtenl==8
replace prtyfam_lmn=41     if prtvtfnl==1
replace prtyfam_lmn=21     if prtvtfnl==2
replace prtyfam_parlgov=86 if prtvtfnl==3
replace prtyfam_lmn=21     if prtvtfnl==4
replace prtyfam_lmn=51     if prtvtfnl==5
replace prtyfam_lmn=41     if prtvtfnl==6
replace prtyfam_lmn=52     if prtvtfnl==7
replace prtyfam_parlgov=31 if prtvtfnl==8
replace prtyfam_lmn=41     if prtvtgnl==1
replace prtyfam_lmn=21     if prtvtgnl==2 /*labour*/
replace prtyfam_parlgov=86 if prtvtgnl==3
replace prtyfam_lmn=21     if prtvtgnl==4
replace prtyfam_lmn=51     if prtvtgnl==5
replace prtyfam_lmn=41     if prtvtgnl==6
replace prtyfam_lmn=52     if prtvtgnl==7
replace prtyfam_parlgov=31 if prtvtgnl==8

replace prtyfam_lmn=41     if prtvthnl==1
replace prtyfam_lmn=21     if prtvthnl==2 /*labour*/
replace prtyfam_parlgov=86 if prtvthnl==3
replace prtyfam_lmn=21     if prtvthnl==4
replace prtyfam_lmn=51     if prtvthnl==5
replace prtyfam_lmn=41     if prtvthnl==6
replace prtyfam_lmn=52     if prtvthnl==7
replace prtyfam_parlgov=31 if prtvthnl==8

**Luxembourg**
replace prtyfam_lmn=51  if prtvtlu==1
replace prtyfam_lmn=21  if prtvtlu==2
replace prtyfam_lmn=41  if prtvtlu==3
replace prtyfam_ours=31 if prtvtlu==4
replace prtyfam_lmn=11  if prtvtlu==5
replace prtyfam_ours=71   if prtvtlu==6

**Norway**
*replace prtyfam_lmn=22  if prtvtno==1
replace prtyfam_lmn=21  if prtvtno==2
replace prtyfam_lmn=21  if prtvtno==3
replace prtyfam_lmn=41  if prtvtno==4
replace prtyfam_lmn=51  if prtvtno==5
replace prtyfam_glm=52  if prtvtno==5
replace prtyfam_lmn=61  if prtvtno==6
replace prtyfam_lmn=71  if prtvtno==7
replace prtyfam_lmn=86  if prtvtno==8
replace prtyfam_glm=82  if prtvtno==8
replace prtyfam_gn=83   if prtvtno==8
replace prtyfam_lmn=21  if prtvtano==2
replace prtyfam_lmn=21  if prtvtano==3
replace prtyfam_lmn=41  if prtvtano==4
replace prtyfam_lmn=51  if prtvtano==5
replace prtyfam_glm=52  if prtvtano==5
replace prtyfam_lmn=61  if prtvtano==6
replace prtyfam_lmn=71  if prtvtano==7
replace prtyfam_lmn=86  if prtvtano==8
replace prtyfam_glm=82  if prtvtano==8
replace prtyfam_gn=83   if prtvtano==8
replace prtyfam_lmn=21  if prtvtbno==2
replace prtyfam_lmn=21  if prtvtbno==3
replace prtyfam_lmn=41  if prtvtbno==4
replace prtyfam_lmn=51  if prtvtbno==5
replace prtyfam_glm=52  if prtvtbno==5
replace prtyfam_lmn=61  if prtvtbno==6
replace prtyfam_lmn=71  if prtvtbno==7
replace prtyfam_lmn=86  if prtvtbno==8
replace prtyfam_glm=82  if prtvtbno==8
replace prtyfam_gn=83   if prtvtbno==8

**UK**
replace prtyfam_lmn=71 	   if prtvtgb==1
replace prtyfam_lmn=21     if prtvtgb==2
replace prtyfam_glm=21     if prtvtgb==2
replace prtyfam_lmn=41     if prtvtgb==3
replace prtyfam_glm=41     if prtvtgb==3
replace prtyfam_lmn=91     if prtvtgb==4
replace prtyfam_lmn=91     if prtvtgb==5
replace prtyfam_parlgov=71 if prtvtgb==11
replace prtyfam_parlgov=71 if prtvtgb==12
replace prtyfam_parlgov=11 if prtvtgb==13
replace prtyfam_lmn=22     if prtvtgb==14/*Social Democratic and Labour Party (nir) */
replace prtyfam_glm=41     if prtvtgb==14
replace prtyfam_parlgov=22 if prtvtgb==14
replace prtyfam_lmn=71     if prtvtagb==1
replace prtyfam_lmn=21     if prtvtagb==2
replace prtyfam_glm=21     if prtvtagb==2
replace prtyfam_lmn=41     if prtvtagb==3
replace prtyfam_glm=41     if prtvtagb==3
replace prtyfam_lmn=91     if prtvtagb==4
replace prtyfam_lmn=91     if prtvtagb==5
replace prtyfam_parlgov=71 if prtvtagb==11
replace prtyfam_parlgov=71 if prtvtagb==12
replace prtyfam_parlgov=11 if prtvtagb==13
replace prtyfam_parlgov=22 if prtvtagb==14
replace prtyfam_lmn=71     if prtvtbgb==1
replace prtyfam_lmn=21     if prtvtbgb==2
replace prtyfam_glm=21     if prtvtbgb==2
replace prtyfam_lmn=41     if prtvtbgb==3
replace prtyfam_glm=41     if prtvtbgb==3
replace prtyfam_lmn=91     if prtvtbgb==4
replace prtyfam_lmn=91     if prtvtbgb==5
replace prtyfam_ours=81    if prtvtbgb==7
replace prtyfam_ours=71    if prtvtbgb==9
replace prtyfam_ours=71    if prtvtbgb==10
replace prtyfam_ours=11    if prtvtbgb==11
replace prtyfam_ours=22    if prtvtbgb==12 /*Social Democratic and Labour Party (nir) */
replace prtyfam_lmn=71     if prtvtcgb==1
replace prtyfam_lmn=21     if prtvtcgb==2
replace prtyfam_glm=21     if prtvtcgb==2
replace prtyfam_lmn=41     if prtvtcgb==3
replace prtyfam_glm=41     if prtvtcgb==3
replace prtyfam_lmn=91     if prtvtcgb==4
replace prtyfam_ours=71    if prtvtcgb==10
replace prtyfam_ours=11    if prtvtcgb==11
replace prtyfam_lmn=71     if prtvtdgb==1
replace prtyfam_lmn=21     if prtvtdgb==2
replace prtyfam_glm=21     if prtvtdgb==2
replace prtyfam_lmn=41     if prtvtdgb==3
replace prtyfam_glm=41     if prtvtdgb==3
replace prtyfam_lmn=91     if prtvtdgb==4

**Switzerland**
replace prtyfam_lmn=41 	   if prtvtch==1
replace prtyfam_parlgov=41 if prtvtch==1
replace prtyfam_lmn=51     if prtvtch==2
replace prtyfam_parlgov=52 if prtvtch==2
replace prtyfam_lmn=21     if prtvtch==3
replace prtyfam_parlgov=21 if prtvtch==3 /*social democrats*/
replace prtyfam_lmn=61     if prtvtch==4
replace prtyfam_parlgov=61 if prtvtch==4
replace prtyfam_ours=85    if prtvtch==4
replace prtyfam_lmn=61     if prtvtch==4
replace prtyfam_lmn=41     if prtvtch==5
replace prtyfam_parlgov=41 if prtvtch==5
replace prtyfam_parlgov=52 if prtvtch==7
replace prtyfam_parlgov=52 if prtvtch==8
replace prtyfam_parlgov=31 if prtvtch==10
replace prtyfam_ours=81     if prtvtch==11
replace prtyfam_parlgov=71 if prtvtch==12
replace prtyfam_parlgov=82 if prtvtch==15
replace prtyfam_ours=82    if prtvtch==15
replace prtyfam_lmn=41     if prtvtach==1
replace prtyfam_parlgov=41 if prtvtach==1
replace prtyfam_lmn=51     if prtvtach==2
replace prtyfam_parlgov=52 if prtvtach==2
replace prtyfam_lmn=21     if prtvtach==3 
replace prtyfam_parlgov=21 if prtvtach==3
replace prtyfam_lmn=61     if prtvtach==4
replace prtyfam_parlgov=61 if prtvtach==4
replace prtyfam_ours=85    if prtvtach==4
replace prtyfam_lmn=61     if prtvtach==4
replace prtyfam_lmn=41     if prtvtach==5
replace prtyfam_parlgov=41 if prtvtach==5
replace prtyfam_parlgov=52 if prtvtach==7
replace prtyfam_parlgov=52 if prtvtach==8
replace prtyfam_parlgov=31 if prtvtach==10
replace prtyfam_ours=81    if prtvtach==11
replace prtyfam_parlgov=71 if prtvtach==12
replace prtyfam_parlgov=82 if prtvtach==15
replace prtyfam_ours=82    if prtvtach==15
replace prtyfam_lmn=41     if prtvtbch==1
replace prtyfam_parlgov=41 if prtvtbch==1
replace prtyfam_lmn=51     if prtvtbch==2
replace prtyfam_parlgov=52 if prtvtbch==2
replace prtyfam_lmn=21     if prtvtbch==3
replace prtyfam_parlgov=21 if prtvtbch==3
replace prtyfam_lmn=61     if prtvtbch==4
replace prtyfam_parlgov=61 if prtvtbch==4
replace prtyfam_ours=85    if prtvtbch==4
replace prtyfam_lmn=61     if prtvtbch==4
replace prtyfam_lmn=41     if prtvtbch==5
replace prtyfam_parlgov=41 if prtvtbch==5
replace prtyfam_parlgov=52 if prtvtbch==6
replace prtyfam_parlgov=11 if prtvtbch==7
replace prtyfam_parlgov=31 if prtvtbch==8
replace prtyfam_parlgov=31 if prtvtbch==9
replace prtyfam_parlgov=71 if prtvtbch==11
replace prtyfam_parlgov=52 if prtvtbch==12
replace prtyfam_parlgov=82 if prtvtbch==13
replace prtyfam_ours=82    if prtvtbch==13
replace prtyfam_lmn=41     if prtvtcch==1
replace prtyfam_parlgov=41 if prtvtcch==1
replace prtyfam_lmn=51     if prtvtcch==2
replace prtyfam_parlgov=52 if prtvtcch==2
replace prtyfam_lmn=21     if prtvtcch==3
replace prtyfam_parlgov=21 if prtvtcch==3
replace prtyfam_lmn=61     if prtvtcch==4
replace prtyfam_parlgov=61 if prtvtcch==4
replace prtyfam_ours=85    if prtvtcch==4
replace prtyfam_lmn=41     if prtvtcch==5
replace prtyfam_parlgov=41 if prtvtcch==5
replace prtyfam_parlgov=52 if prtvtcch==6
replace prtyfam_parlgov=11 if prtvtcch==7
replace prtyfam_parlgov=31 if prtvtcch==8
replace prtyfam_parlgov=31 if prtvtcch==9
replace prtyfam_ours=81    if prtvtcch==10
replace prtyfam_parlgov=71 if prtvtcch==11
replace prtyfam_parlgov=52 if prtvtcch==12
replace prtyfam_parlgov=82 if prtvtcch==13
replace prtyfam_ours=82    if prtvtcch==13
replace prtyfam_lmn=61     if prtvtdch==1
replace prtyfam_parlgov=61 if prtvtdch==1
replace prtyfam_ours=85    if prtvtdch==1
replace prtyfam_parlgov=21 if prtvtdch==2
replace prtyfam_lmn=41     if prtvtdch==3
replace prtyfam_parlgov=41 if prtvtdch==3
replace prtyfam_lmn=51     if prtvtdch==4
replace prtyfam_parlgov=52 if prtvtdch==4
replace prtyfam_parlgov=31 if prtvtdch==5
replace prtyfam_parlgov=31 if prtvtcch==6
replace prtyfam_parlgov=71 if prtvtdch==7
replace prtyfam_parlgov=52 if prtvtdch==8
replace prtyfam_parlgov=82 if prtvtdch==12
replace prtyfam_ours=82    if prtvtdch==12
replace prtyfam_lmn=61     if prtvtech==1
replace prtyfam_parlgov=61 if prtvtech==1
replace prtyfam_ours=85    if prtvtech==1
replace prtyfam_parlgov=21 if prtvtech==2
replace prtyfam_lmn=41     if prtvtech==3
replace prtyfam_parlgov=41 if prtvtech==3
replace prtyfam_lmn=51     if prtvtech==4
replace prtyfam_parlgov=52 if prtvtech==4
replace prtyfam_parlgov=31 if prtvtech==5
replace prtyfam_parlgov=31 if prtvtech==6
replace prtyfam_parlgov=71 if prtvtech==7
replace prtyfam_parlgov=52 if prtvtech==8
replace prtyfam_ours=81    if prtvtech==10
replace prtyfam_parlgov=82 if prtvtech==12
replace prtyfam_ours=82    if prtvtech==12
replace prtyfam_lmn=61     if prtvtfch==1
replace prtyfam_parlgov=61 if prtvtfch==1
replace prtyfam_ours=85    if prtvtfch==1
replace prtyfam_parlgov=21 if prtvtfch==2
replace prtyfam_lmn=41     if prtvtfch==3
replace prtyfam_parlgov=41 if prtvtfch==3
replace prtyfam_lmn=51     if prtvtfch==4
replace prtyfam_parlgov=52 if prtvtfch==4
replace prtyfam_parlgov=31 if prtvtfch==5
replace prtyfam_parlgov=31 if prtvtfch==6
replace prtyfam_parlgov=71 if prtvtfch==7
replace prtyfam_parlgov=52 if prtvtfch==8
replace prtyfam_ours=81      if prtvtfch==10
replace prtyfam_ours=11      if prtvtfch==11
replace prtyfam_lmn=61     if prtvtgch==1
replace prtyfam_parlgov=61 if prtvtgch==1
replace prtyfam_ours=85    if prtvtgch==1 /*svp*/
replace prtyfam_parlgov=21 if prtvtgch==2
replace prtyfam_lmn=41     if prtvtgch==3
replace prtyfam_parlgov=41 if prtvtgch==3
replace prtyfam_lmn=51     if prtvtgch==4
replace prtyfam_parlgov=52 if prtvtgch==4
replace prtyfam_parlgov=31 if prtvtgch==5
replace prtyfam_parlgov=31 if prtvtgch==6
replace prtyfam_parlgov=71 if prtvtgch==7
replace prtyfam_parlgov=52 if prtvtgch==8
replace prtyfam_ours=81      if prtvtgch==10
replace prtyfam_lmn=61     if prtvthch==1
replace prtyfam_parlgov=61 if prtvthch==1
replace prtyfam_ours=85    if prtvthch==1 /*svp*/
replace prtyfam_parlgov=21 if prtvthch==2
replace prtyfam_lmn=41     if prtvthch==3
replace prtyfam_parlgov=41 if prtvthch==3
replace prtyfam_lmn=31     if prtvthch==4
replace prtyfam_parlgov=51 if prtvthch==5
replace prtyfam_parlgov=31 if prtvthch==6
replace prtyfam_parlgov=71 if prtvthch==7
replace prtyfam_parlgov=52 if prtvthch==8

**france**
replace prtyfam_ours=41     if prtvtfr==2
replace prtyfam_parlgov=71 if prtvtfr==8
replace prtyfam_lmn=11     if prtvtfr==9
replace prtyfam_lmn=21     if prtvtfr==10 /*ps*/
replace prtyfam_ours=71    if prtvtfr==11
replace prtyfam_lmn=71     if prtvtfr==12
replace prtyfam_lmn=71     if prtvtfr==13
replace prtyfam_lmn=31     if prtvtfr==14
replace prtyfam_lmn=41     if prtvtafr==2
replace prtyfam_parlgov=71 if prtvtafr==8
replace prtyfam_lmn=11 	   if prtvtafr==9
replace prtyfam_lmn=21     if prtvtafr==10
replace prtyfam_ours=71    if prtvtafr==11
replace prtyfam_lmn=71     if prtvtafr==12
replace prtyfam_lmn=71     if prtvtafr==13
replace prtyfam_lmn=31     if prtvtafr==14
replace prtyfam_ours=71    if prtvtbfr==5
replace prtyfam_parlgov=41 if prtvtbfr==6
replace prtyfam_lmn=11     if prtvtbfr==7 
replace prtyfam_lmn=21     if prtvtbfr==8/*ps*/
replace prtyfam_lmn=41     if prtvtbfr==9
replace prtyfam_parlgov=22 if prtvtbfr==9 /*PRG (Parti Radical de Gauche)*/
replace prtyfam_parlgov=41 if prtvtbfr==10
replace prtyfam_lmn=71     if prtvtbfr==11
replace prtyfam_lmn=31     if prtvtbfr==12
replace prtyfam_lmn=41 	   if prtvtcfr==1
replace prtyfam_parlgov=81 if prtvtcfr==2
replace prtyfam_ours=41    if prtvtcfr==3
replace prtyfam_ours=22    if prtvtcfr==6 /* FDG (Front de Gauche)*/
replace prtyfam_parlgov=22 if prtvtcfr==7 /*Parti Radical de Gauche */
replace prtyfam_lmn=21     if prtvtcfr==9 /*ps*/
replace prtyfam_lmn=71     if prtvtcfr==10
replace prtyfam_parlgov=41 if prtvtcfr==11
replace prtyfam_lmn=31     if prtvtcfr==12
replace prtyfam_lmn=11 	   if prtvtdfr==1
replace prtyfam_parlgov=11 if prtvtdfr==3
replace prtyfam_ours=22    if prtvtdfr==4 /*fi*/
replace prtyfam_parlgov=21 if prtvtdfr==5 /*ps*/
replace prtyfam_lmn=31     if prtvtdfr==6 /*eelv*/
replace prtyfam_lmn=41     if prtvtdfr==7 /*lrem*/
replace prtyfam_parlgov=41 if prtvtdfr==8 /*modem*/
replace prtyfam_lmn=71     if prtvtdfr==9 /*lr*/
replace prtyfam_lmn=81     if prtvtdfr==10 /*dlf*/
replace prtyfam_parlgov=81 if prtvtdfr==11 /*fn*/
replace prtyfam_lmn=11 	   if prtvtefr==1 /*lo*/
replace prtyfam_parlgov=11 if prtvtefr==3 /*pcf*/
replace prtyfam_ours=22    if prtvtefr==4 /*fi*/
replace prtyfam_parlgov=21 if prtvtefr==5 /*ps*/
replace prtyfam_lmn=31     if prtvtefr==6 /*eelv*/
replace prtyfam_lmn=41     if prtvtefr==7 /*lrem*/
replace prtyfam_parlgov=41 if prtvtefr==8 /*modem*/
replace prtyfam_lmn=71     if prtvtefr==9 /*lr*/
replace prtyfam_lmn=81     if prtvtefr==10 /*dlf*/
replace prtyfam_parlgov=81 if prtvtefr==11 /*fn*/

**portugal**
replace prtyfam_parlgov=11 if prtvtpt==1
replace prtyfam_lmn=52     if prtvtpt==2
replace prtyfam_lmn=11     if prtvtpt==5
replace prtyfam_lmn=21     if prtvtpt==10 /* PS - Partido Socialista */
replace prtyfam_lmn=41     if prtvtpt==11
replace prtyfam_parlgov=11 if prtvtapt==1
replace prtyfam_lmn=52     if prtvtapt==2
replace prtyfam_lmn=11     if prtvtapt==3
replace prtyfam_lmn=41     if prtvtapt==10
replace prtyfam_lmn=21     if prtvtapt==11
replace prtyfam_parlgov=11 if prtvtbpt==1
replace prtyfam_lmn=52     if prtvtbpt==2
replace prtyfam_parlgov=11 if prtvtbpt==3
replace prtyfam_lmn=41     if prtvtbpt==10
replace prtyfam_lmn=21     if prtvtbpt==11
replace prtyfam_parlgov=11 if prtvtcpt==2
replace prtyfam_lmn=11     if prtvtcpt==3
replace prtyfam_parlgov=21 if prtvtcpt==13
replace prtyfam_lmn=41     if prtvtcpt==16
replace prtyfam_parlgov=11 if prtvtdpt==2
replace prtyfam_lmn=41     if prtvtdpt==3
replace prtyfam_parlgov=81 if prtvtdpt==4 /*chega*/
replace prtyfam_lmn=11     if prtvtdpt==12
replace prtyfam_parlgov=21 if prtvtdpt==16 /*psd*/
replace prtyfam_lmn=21     if prtvtdpt==18 /*ps*/

*Sweden*
replace prtyfam_lmn=61  	if prtvtse==1
replace prtyfam_lmn=41  	if prtvtse==2
replace prtyfam_lmn=52  	if prtvtse==3
replace prtyfam_gn=51   	if prtvtse==3
replace prtyfam_lmn=31  	if prtvtse==4
replace prtyfam_lmn=71  	if prtvtse==5
replace prtyfam_lmn=21  	if prtvtse==6 /*Social Democrats*/
replace prtyfam_lmn=11  	if prtvtse==7
replace prtyfam_lmn=61  	if prtvtase==1
replace prtyfam_lmn=41  	if prtvtase==2
replace prtyfam_lmn=52  	if prtvtase==3
replace prtyfam_gn=51   	if prtvtase==3
replace prtyfam_lmn=31  	if prtvtase==4
replace prtyfam_lmn=71  	if prtvtase==5
replace prtyfam_lmn=21  	if prtvtase==6
replace prtyfam_lmn=11  	if prtvtase==7
replace prtyfam_ours=85 	if prtvtase==10
replace prtyfam_parlgov=83  if prtvtase==10

replace prtyfam_lmn=61      if prtvtbse==1
replace prtyfam_lmn=41      if prtvtbse==2
replace prtyfam_lmn=52      if prtvtbse==3
replace prtyfam_gn=51       if prtvtbse==3
replace prtyfam_lmn=31      if prtvtbse==4
replace prtyfam_lmn=71      if prtvtbse==5
replace prtyfam_lmn=21      if prtvtbse==6
replace prtyfam_lmn=11      if prtvtbse==7
replace prtyfam_ours=85     if prtvtbse==10
replace prtyfam_parlgov=83  if prtvtbse==10
replace prtyfam_lmn=61      if prtvtcse==1
replace prtyfam_lmn=41      if prtvtcse==2
replace prtyfam_lmn=52      if prtvtcse==3
replace prtyfam_gn=51       if prtvtcse==3
replace prtyfam_lmn=31      if prtvtcse==4
replace prtyfam_lmn=71      if prtvtcse==5
replace prtyfam_lmn=21      if prtvtcse==6
replace prtyfam_lmn=11      if prtvtcse==7
replace prtyfam_ours=85     if prtvtcse==9
replace prtyfam_parlgov=83  if prtvtcse==9
replace prtyfam_lmn=61      if prtvtdse==1
replace prtyfam_lmn=51      if prtvtdse==2
replace prtyfam_lmn=41      if prtvtdse==3
replace prtyfam_gn=42       if prtvtdse==3
replace prtyfam_lmn=31      if prtvtdse==4
replace prtyfam_lmn=71      if prtvtdse==5
replace prtyfam_lmn=21      if prtvtdse==6
replace prtyfam_lmn=81      if prtvtdse==7
replace prtyfam_ours=11     if prtvtdse==8

*Spain*
replace prtyfam_lmn=71  	if prtvtes==1
replace prtyfam_lmn=21  	if prtvtes==2 /*psoe*/
replace prtyfam_ours=12 	if prtvtes==3
replace prtyfam_lmn=91  	if prtvtes==4
replace prtyfam_ours=41 	if prtvtes==4
replace prtyfam_lmn=91  	if prtvtes==5
replace prtyfam_ours=41 	if prtvtes==5
replace prtyfam_parlgov=31  if prtvtes==6
replace prtyfam_ours=42 	if prtvtes==7
replace prtyfam_ours=42 	if prtvtes==8
replace prtyfam_lmn=91 		if prtvtes==9
replace prtyfam_lmn=91 		if prtvtes==10
replace prtyfam_ours=22 	if prtvtes==11 /* Partido Andalucista */
replace prtyfam_ours=91 	if prtvtes==12
replace prtyfam_lmn=71 		if prtvtaes==1
replace prtyfam_lmn=21 		if prtvtaes==2
replace prtyfam_ours=12 	if prtvtaes==3
replace prtyfam_lmn=91  	if prtvtaes==4
replace prtyfam_ours=41 	if prtvtaes==4
replace prtyfam_lmn=91 		if prtvtaes==5
replace prtyfam_ours=41 	if prtvtaes==5
replace prtyfam_ours=42 	if prtvtaes==7
replace prtyfam_ours=42 	if prtvtaes==8
replace prtyfam_lmn=91 		if prtvtaes==9
replace prtyfam_lmn=91 		if prtvtaes==10
replace prtyfam_ours=91 	if prtvtaes==12
replace prtyfam_ours=91 	if prtvtaes==13
replace prtyfam_lmn=71 		if prtvtbes==1
replace prtyfam_lmn=21 		if prtvtbes==2
replace prtyfam_ours=12 	if prtvtbes==3
replace prtyfam_lmn=91 		if prtvtbes==4
replace prtyfam_ours=41 	if prtvtbes==4
replace prtyfam_lmn=91 		if prtvtbes==5
replace prtyfam_ours=41 	if prtvtbes==5
replace prtyfam_ours=42 	if prtvtbes==6
replace prtyfam_lmn=91 		if prtvtbes==7
replace prtyfam_lmn=91 		if prtvtbes==8
replace prtyfam_ours=91 	if prtvtbes==9
replace prtyfam_parlgov=41  if prtvtbes==10
replace prtyfam_lmn=71 		if prtvtces==1
replace prtyfam_lmn=21 		if prtvtces==2
replace prtyfam_lmn=91 		if prtvtces==3
replace prtyfam_ours=12 	if prtvtces==4
replace prtyfam_ours=65 	if prtvtces==5 
replace prtyfam_parlgov=41  if prtvtces==6
replace prtyfam_lmn=42 		if prtvtces==7
replace prtyfam_lmn=91      if prtvtces==8
replace prtyfam_lmn=91 		if prtvtces==9
replace prtyfam_lmn=91 		if prtvtces==10
replace prtyfam_lmn=91 		if prtvtces==11
replace prtyfam_parlgov=71  if prtvtces==12
replace prtyfam_lmn=71 		if prtvtdes==1
replace prtyfam_lmn=21 		if prtvtdes==2
replace prtyfam_lmn=11 		if prtvtdes==3
replace prtyfam_ours=41 	if prtvtdes==5
replace prtyfam_ours=11 	if prtvtdes==7 
replace prtyfam_lmn=11 		if prtvtdes==8
replace prtyfam_lmn=91 		if prtvtdes==10
replace prtyfam_lmn=91 		if prtvtdes==11
replace prtyfam_ours=12 	if prtvtdes==14
replace prtyfam_lmn=71 		if prtvtees==1
replace prtyfam_lmn=21 		if prtvtees==2
replace prtyfam_lmn=11 		if prtvtees==3
replace prtyfam_ours=41 	if prtvtees==5
replace prtyfam_ours=91 	if prtvtees==10
 
/* Turning wide vote choice variables to long: 
   ESS dataset was organized such that every country (c)/ wave (j) had a vote choice 
   variable. These data look like a block Swiss cheese dataset, where for every such 
   variable there is an N(cj)-element column of vote-choice responses and missing entries 
   for the rest of the N observations in the dataset. Here, we generate a single 
   variable that "aggregates" across columns and collapses these cj columns into one */

egen votechoice=rowtotal(prtvtat prtvtaat prtvtbat prtvtcat prtvtbe prtvtabe prtvtbbe prtvtcbe prtvtdbe prtvtebe /// 
	 prtvtch prtvtach prtvtbch prtvtcch prtvtdch prtvtech prtvtfch prtvtgch prtvthch prtvde2 prtvade2 prtvbde2 prtvcde2 /// 
	 prtvdde2 prtvede2 prtvfde2 prtvtdk prtvtadk prtvtbdk prtvtcdk prtvtddk prtvtes prtvtaes prtvtbes prtvtces prtvtdes prtvtees prtvtfes ///
	 prtvtfi prtvtafi prtvtbfi prtvtcfi prtvtdfi prtvtdfi prtvtefi prtvtfr  prtvtafr prtvtbfr prtvtcfr prtvtdfr prtvtefr prtvtgb /// 
	 prtvtagb prtvtbgb prtvtcgb prtvtgr prtvtagr prtvtbgr prtvtcgr prtvtdgr prtvtie prtvtaie prtvtbie prtvtcie prtvtdie prtvtis prtvtais prtvtbis prtvtcis prtvtdis ///
	 prtvtit prtvtait prtvtbit prtvtcit prtvtdit prtvtnl prtvtanl prtvtbnl prtvtcnl prtvtdnl prtvtenl prtvtfnl prtvtgnl prtvthnl ///
	  prtvtno prtvtano prtvtbno prtvtpt prtvtapt prtvtbpt prtvtcpt prtvtdpt prtvtse prtvtase prtvtbse prtvtcse prtvtdse prtvtlu prtvtcat prtvtdbe prtvtebe prtvtgch prtvthch prtvfde2 prtvtddk prtvtees prtvtfes prtvtefi prtvtdfr prtvtefr prtvtcgb prtvtdgb prtvtdgr prtvtcie prtvtdie prtvtcis prtvtdis prtvtcit prtvtdit prtvtgnl prtvthnl prtvtdpt prtvtdse) 

/* Party families: indicates if respondent voted for a party included in the 
   party family	*/
gen prtyfam_rr=.
gen prtyfam_left=.
gen prtyfam_grn=.
gen prtyfam_cd=.
gen prtyfam_cons=.
gen prtyfam_radicalleft=.
gen prtyfam_lib=.
gen prtyfam_sd=.

replace prtyfam_rr = (prtyfam_lmn<=86&prtyfam_lmn>=81)|(prtyfam_glm<=86&prtyfam_glm>=81) | ///
	(prtyfam_gn<=86&prtyfam_gn>=81)|(prtyfam_ours<=86&prtyfam_ours>=81) |(prtyfam_parlgov<=86&prtyfam_parlgov>=81)
	
replace prtyfam_left = (prtyfam_lmn==22|prtyfam_lmn==21)|(prtyfam_glm==22|prtyfam_glm==21) | ///
	(prtyfam_ours==22|prtyfam_ours==21)|(prtyfam_parlgov==22|prtyfam_parlgov==21)
	
replace prtyfam_sd = (prtyfam_lmn==21)|(prtyfam_glm==21) | ///
	(prtyfam_ours==21)|(prtyfam_parlgov==21)
	
replace prtyfam_cd = (prtyfam_lmn<=59&prtyfam_lmn>=50)|(prtyfam_glm<=59&prtyfam_glm>=50) | ///
	(prtyfam_gn<=59&prtyfam_gn>=50)|(prtyfam_ours<=59&prtyfam_ours>=50) |(prtyfam_parlgov<=59&prtyfam_parlgov>=50)
	
replace prtyfam_cons = (prtyfam_lmn<=79&prtyfam_lmn>=70)|(prtyfam_glm<=79&prtyfam_glm>=70) | ///
	(prtyfam_gn<=79&prtyfam_gn>=70)|(prtyfam_ours<=79&prtyfam_ours>=70)|(prtyfam_parlgov<=79&prtyfam_parlgov>=70)
	
replace prtyfam_radicalleft = (prtyfam_lmn==11|prtyfam_lmn==12)|(prtyfam_glm==11|prtyfam_glm==12) | ///
	(prtyfam_ours==11|prtyfam_ours==12) |(prtyfam_parlgov==11|prtyfam_parlgov==12) |(prtyfam_lmn==22)|(prtyfam_glm==22) | ///
	(prtyfam_ours==22)|(prtyfam_parlgov==22)
	
replace prtyfam_lib = (prtyfam_lmn==41|prtyfam_lmn==42)|(prtyfam_glm==41|prtyfam_glm==42) | ///
	(prtyfam_ours==41|prtyfam_ours==42) | (prtyfam_gn==41|prtyfam_gn==42) |(prtyfam_parlgov==41|prtyfam_parlgov==42)
	
replace prtyfam_grn= prtyfam_lmn==31 ///
    |prtyfam_glm==31 | ///
	prtyfam_ours==31 |prtyfam_parlgov==31

/*CATEGORICAL VAR. OF PARTY FAMILIES, BASE CATEGORY(0) LEFT*/
gen     prtyfam_vote = 0 if prtyfam_sd==1
replace prtyfam_vote = 1 if prtyfam_radicalleft==1   
replace prtyfam_vote = 2 if prtyfam_cd==1   
replace prtyfam_vote = 3 if prtyfam_cons==1	   
replace prtyfam_vote = 4 if prtyfam_grn==1
replace prtyfam_vote = 5 if prtyfam_rr==1
replace prtyfam_vote = 6 if prtyfam_lib==1
 

label define prtyfam 0 "Social Demo." 1 "Radical Left" 2 "Christ. Dems." 3 "Conservatives" 4 "Greens" 5 "rr" 6 "liberals", replace
label values prtyfam_vote prtyfam
	
	
	
/*  Generate the vote share variabes for different party families 
	Numerator:   number of imigrants in country C, in round j, who voted for rr
	Denominator: number of immigrants in country C, in round j (who voted, screening for turnout above)*/

by cntry essround imgstatus, sort: egen countimgrr=count(imgstatus) if prtyfam_rr==1 & (imgstatus==4 | imgstatus==5) & vote==1
by cntry essround imgstatus, sort: egen countimgpf=count(imgstatus) if (imgstatus==4 | imgstatus==5) & vote==1
gen     vsimgpfrr = .
replace vsimgpfrr = countimgrr/countimgpf 

by cntry essround imgstatus, sort: egen countntvrr=count(imgstatus) if prtyfam_rr==1 & (mstatus==1) & vote==1
by cntry essround imgstatus, sort: egen countntvpf=count(imgstatus) if (mstatus==1) & vote==1
gen     vsntvpfrr = .
replace vsntvpfrr = countntvrr/countntvpf 


by cntry essround prtyfam_rr, sort: egen vsimgpfrrunique=max(vsimgpfrr)

by cntry essround prtyfam_rr, sort: egen vsntvpfrrunique=max(vsntvpfrr)

*   RR immigrant-native gap 
gen imgntvgappfrr=vsimgpfrrunique-vsntvpfrrunique 
ta imgntvgappfrr /*67% negative gap*/

/* Generate the imigrant specific vote share variabe for Left 
   Numerator: number of non western immigrants in country C, in round j, who voted for left 
   Denominator: number of non western immigrants in country C, in round j (who voted, screening for turnout above)*/
by cntry essround imgstatus, sort: egen countimgl=count(imgstatus) if prtyfam_sd==1 & (imgstatus==4 | imgstatus==5) & vote==1

gen     vsimgpfl = .
replace vsimgpfl = countimgl/countimgpf  

by cntry essround prtyfam_sd, sort: egen vsimgpflunique=max(vsimgpfl)

by cntry essround imgstatus, sort: egen countntvl=count(imgstatus) if prtyfam_sd==1 & (mstatus==1) & vote==1
gen     vsntvpfl = .
replace vsntvpfl = countntvl/countntvpf 

by cntry essround prtyfam_sd, sort: egen vsntvpflunique=max(vsntvpfl)


* sd immigrant-native gap 
gen imgntvgappfl=vsimgpflunique-vsntvpflunique
ta imgntvgappfl

/* Generate the muslim  vote share variabe for sd 
   Numerator: number of muslims in country C, in round j, who voted for sd 
   Denominator: number of muslims in country C, in round j (who voted, screening for turnout above)*/
by cntry essround muslim, sort: egen countmsll=count(muslim) if prtyfam_sd==1 & muslim==1 & vote==1
by cntry essround muslim, sort: egen countmslpf=count(muslim) if muslim==1 & vote==1
gen     vsmslpfl = .
replace vsmslpfl = countmsll/countmslpf  

by cntry essround prtyfam_sd, sort: egen vsmslpflunique=max(vsmslpfl)


* SD immigrant-native gap 
gen mslntvgappfl=vsmslpflunique-vsntvpflunique
ta mslntvgappfl



/* preparation for aggregate figures of the gender gaps*/


* Unique gender gap variable for every year and country : Left
egen lunique=tag(imgntvgappfl cntryear)
by cntry essround, sort: egen lunique1=max(imgntvgappfl) if lunique==1

gen lper = lunique1*100

egen lunique2=tag(mslntvgappfl cntryear)
by cntry essround, sort: egen lunique3=max(mslntvgappfl) if lunique2==1

gen lpermsl = lunique3*100

* Figure 1: gap muslim-native for the left overtime

*transperant CIs
set scheme plottig
grstyle init
grstyle set ci 
grstyle color ci_area gs1%70
grstyle set nogrid
grstyle set linewidth 15pt: plineplot

set scheme plotplain
twoway lpolyci lpermsl year , degree(2) level(95) clstyle(p1line) lcol(black) fcolor(gs8*.7) acolor(538rs9%50) lwidth(thick) lpattern(solid) yline(0) ytitle("Muslims–non-Muslims gap in the vote for leftwing parties") xtitle("") caption(Source: ESS 1-10)xtitle("") msymbol (i)  yscale(r(-20(20) 80)) xscale(r(2002(2)2020)) graphregion(color(white)) ylabel(,nogrid)legend(off) 
graph save "Figure 1", replace										   

/*APPENDIX - FIGURE D2*/
twoway scatter lpermsl year if cntry=="ES", yline(0) ytitle("") xtitle("") ///
										   caption(Source: Source: ESS1-10)  /// 
										   xtitle("") mlabel (cntry) msymbol (i)  ///
										    graphregion(color(white)) legend(off) ///
										   ylabel(,nogrid)  ///
		||scatter lpermsl year if cntry=="GB",  mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="IE", mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="LU", mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="PT", mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="DE" , mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="AT" , mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="BE" , mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="CH" , mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="FR" , mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="GR" , mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="IT"  , mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="NL", mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="SE", mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="NO" , mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="IS" , mlabel (cntry) msymbol (i) ///
		||scatter lpermsl year if cntry=="FI" , mlabel (cntry)msymbol (i) ///
		||scatter lpermsl year if cntry=="DK" , mlabel (cntry)msymbol (i) ///
		||lpolyci lpermsl year ,   degree(2) clstyle(p1line) level(95) 

		
/*VOTESHARE AND SEATSHARE FOR RR PARTIES*/
gen vote_share=.
gen seat_share=.
gen in_parliament=.
gen ever_in_parliament=.
gen in_coalition=.
gen ever_in_coalition=.
gen epvote=.

* AT FPO
replace vote_share=26.9 if prtvtat==3  /*1999 elections (t-1)*/
replace seat_share=28.41 if prtvtat==3 /*1999 elections (t-1)*/
replace in_parliament=1 if prtvtat==3
replace in_coalition=1 if prtvtat==3
replace ever_in_p=1 if prtvtat==3
replace ever_in_c=1 if prtvtat==3
replace epvote=23.4 if prtvtat==3

replace vote_share=10 if prtvtaat==3 /*2002 elections*/
replace seat_share=9.84 if prtvtaat==3
replace in_p=1 if prtvtaat==3 
replace in_c=1 if prtvtaat==3
replace ever_in_p=1 if prtvtaat==3
replace ever_in_c=1 if prtvtaat==3
replace epvote=30.67 if prtvtaat==3

replace vote_share=20.5 if prtvtbat==3 /*2013 elections*/
replace seat_share=21.85 if prtvtbat==3
replace in_p=1 if prtvtbat==3 
replace in_c=0 if prtvtbat==3
replace ever_in_p=1 if prtvtbat==3
replace ever_in_c=1 if prtvtbat==3
replace epvote=19.7 if prtvtbat==3

replace vote_share=16.2 if prtvtcat==3 /*2019 elections*/
replace seat_share=16.9 if prtvtcat==3
replace epvote=17.2 if prtvtcat==3

* AT BZO
replace vote_share=0 if prtvtaat==4
replace seat_share= 0 if prtvtaat==4
replace in_p=0 if prtvtaat==4
replace in_c=0 if prtvtaat==4
replace ever_in_p=0 if prtvtaat==4
replace ever_in_c=0 if prtvtaat==4
replace epvote=0 if prtvtaat==4

replace vote_share=3.5 if prtvtbat==4
replace seat_share=0 if prtvtbat==4
replace in_p=1 if prtvtbat==4
replace in_c=0 if prtvtbat==4
replace ever_in_p=1 if prtvtbat==4
replace ever_in_c=0 if prtvtbat==4
replace epvote=0.5 if prtvtbat==4

* BE FNB
replace vote_share=1.5 if prtvtbe==15
replace seat_share=1.3 if prtvtbe==15
replace in_parliament=1 if prtvtbe==15
replace in_coalition=0 if prtvtbe==15
replace ever_in_p=1 if prtvtbe==15
replace ever_in_c=0 if prtvtbe==15
replace epvote=1.52 if prtvtbe==15

replace vote_share=2 if prtvtabe==11
replace seat_share=0.7 if prtvtabe==11
replace in_parliament=1 if prtvtabe==11
replace in_coalition=0 if prtvtabe==11
replace ever_in_p=1 if prtvtabe==15
replace ever_in_c=0 if prtvtabe==15
replace epvote=1.52 if prtvtabe==15

replace vote_share=2 if prtvtbbe==11 | prtvtcbe==11
replace seat_share=0.7 if prtvtbbe==11 | prtvtcbe==11
replace in_parliament=1 if prtvtbbe==11 | prtvtcbe==11
replace in_coalition=0 if prtvtbbe==11 | prtvtcbe==11
replace ever_in_p=1 if prtvtbbe==11 | prtvtcbe==11
replace ever_in_c=0 if prtvtbbe==11 | prtvtcbe==11
replace epvote=1.52 if prtvtbbe==11 | prtvtcbe==11
* BE VB
replace vote_share=9.87 if prtvtbe==8 /*1999 elections*/
replace seat_share=10 if prtvtbe==8
replace in_parliament=1 if prtvtbe==8
replace in_coalition=0 if prtvtbe==8
replace ever_in_parliament=1 if prtvtbe==8
replace ever_in_coalition=0 if prtvtbe==8
replace epvote=9.39 if prtvtbe==8

replace vote_share=11.6 if prtvtabe==7
replace seat_share=12 if prtvtabe==7
replace in_parliament=1 if prtvtabe==7
replace in_coalition=0 if prtvtabe==7
replace ever_in_parliament=1 if prtvtabe==7
replace ever_in_coalition=0 if prtvtabe==7
replace epvote=14.3 if prtvtabe==7

replace vote_share=12 if prtvtbbe==7
replace seat_share=11.33 if prtvtbbe==7
replace in_parliament=1 if prtvtbbe==7
replace in_coalition=0 if prtvtbbe==7
replace ever_in_parliament=1 if prtvtbbe==7
replace ever_in_coalition=0 if prtvtbbe==7
replace epvote=14.3 if prtvtbbe==7

replace vote_share=7.8 if prtvtcbe==7 & year<2014
replace seat_share=8 if prtvtcbe==7 & year<2014
replace in_parliament=1 if prtvtcbe==7 & year<2014
replace in_coalition=0 if prtvtcbe==7 & year<2014
replace ever_in_parliament=1 if prtvtcbe==7 & year<2014
replace ever_in_coalition=0 if prtvtcbe==7 & year<2014
replace epvote=9.85 if prtvtcbe==7 & year<2014

replace vote_share=3.7 if prtvtcbe==7 & year==2014
replace seat_share=2 if prtvtcbe==7 & year==2014
replace in_parliament=1 if prtvtcbe==7 & year==2014
replace in_coalition=0 if prtvtcbe==7 & year==2014
replace ever_in_parliament=1 if prtvtcbe==7 & year==2014
replace ever_in_coalition=0 if prtvtcbe==7 & year==2014
replace epvote=4.3 if prtvtcbe==7 & year==2014

replace vote_share=3.7 if prtvtcbe==7 & year==2016
replace seat_share=2 if prtvtcbe==7 & year==2016
replace in_parliament=1 if prtvtcbe==7 & year==2016
replace in_coalition=0 if prtvtcbe==7 & year==2016
replace ever_in_parliament=1 if prtvtcbe==7 & year==2016
replace ever_in_coalition=0 if prtvtcbe==7 & year==2016
replace epvote=4.3 if prtvtcbe==7 & year==2016

replace vote_share=3.7 if prtvtdbe==7 
replace seat_share=2 if prtvtdbe==7 
replace epvote=4.3 if prtvtdbe==7 
* DK DF
replace vote_s=12.4 if prtvtdk==6 /*2001 election*/
replace seat_s=12.3 if prtvtdk==6
replace in_p=1 if prtvtdk==6
replace in_c=0 if prtvtdk==6
replace ever_in_p=1 if prtvtdk==6
replace ever_in_c=0 if prtvtdk==6
replace epvote=5.8  if prtvtdk==6

replace vote_s=13.3 if prtvtadk==6 /*2005 elections*/
replace seat_s=13.4 if prtvtadk==6
replace in_p=1 if prtvtadk==6
replace in_c=1 if prtvtadk==6
replace ever_in_p=1 if prtvtadk==6
replace ever_in_c=1 if prtvtadk==6
replace epvote=6.8  if prtvtadk==6

replace vote_s=13.9 if prtvtbdk==5 /*2007 elections*/
replace seat_s=13.9 if prtvtbdk==5
replace in_p=1 if prtvtbdk==5
replace in_c=1 if prtvtbdk==5
replace ever_in_p=1 if prtvtbdk==5
replace ever_in_c=1 if prtvtbdk==5
replace epvote=15.28  if prtvtbdk==5

replace vote_s=12.17 if prtvtcdk==5 /*2011 elections*/
replace seat_s=12.29 if prtvtcdk==5
replace in_p=1 if prtvtcdk==5
replace in_c=0 if prtvtcdk==5
replace ever_in_p=1 if prtvtcdk==5
replace ever_in_c=1 if prtvtcdk==5
replace epvote=26.6  if prtvtcdk==5

replace vote_s=21 if prtvtddk==5 /*2014 elections*/
replace seat_s=21 if prtvtddk==5
replace epvote=26.6  if prtvtddk==5

* FI PS
replace vote_s=.99 if prtvtfi==5 & year==2002 /*99 elections*/
replace seat_s=0.5 if prtvtfi==5 & year==2002
replace in_p=1 if prtvtfi==5 & year==2002
replace in_c=0 if prtvtfi==5 & year==2002
replace ever_in_p=1 if prtvtfi==5 & year==2002
replace ever_in_c=1 if prtvtfi==5 & year==2002
replace epvote=0 if prtvtfi==5 & year==2002

replace vote_s=1.57 if prtvtfi==5 & year!=2002 /*2003 elections*/
replace seat_s=1.5 if prtvtfi==5 & year!=2002
replace in_p=1 if prtvtfi==5 & year!=2002
replace in_c=0 if prtvtfi==5 & year!=2002
replace ever_in_p=1 if prtvtfi==5 & year!=2002
replace ever_in_c=1 if prtvtfi==5 & year!=2002
replace epvote=0.54 if prtvtfi==5 & year!=2002

replace vote_s=4.1 if prtvtafi==5 | prtvtbfi==5 /*2007 elections*/
replace seat_s=2.5 if prtvtafi==5 | prtvtbfi==5
replace in_p=1 if prtvtafi==5 | prtvtbfi==5 
replace in_c=0 if prtvtafi==5 | prtvtbfi==5
replace ever_in_p=1 if prtvtafi==5 | prtvtbfi==5 
replace ever_in_c=1 if prtvtafi==5 | prtvtbfi==5
replace epvote=9.79 if prtvtafi==5 | prtvtbfi==5

replace vote_s=19.1 if prtvtcfi==4 /*2011 elections*/
replace seat_s=19.5 if prtvtcfi==4 
replace in_p=1 if prtvtcfi==4
replace in_c=0 if prtvtcfi==4
replace ever_in_p=1 if prtvtcfi==4
replace ever_in_c=1 if prtvtcfi==4
replace epvote=12.9 if prtvtcfi==4

replace vote_s=17.65 if prtvtdfi==4 /*2015 elections*/
replace seat_s=19 if prtvtdfi==4 
replace in_p=1 if prtvtdfi==4
replace in_c=1 if prtvtdfi==4
replace ever_in_p=1 if prtvtdfi==4
replace ever_in_c=1 if prtvtdfi==4
replace epvote=13.8 if prtvtdfi==4

* FR MNR
replace vote_s=1.09 if prtvtfr==7 | prtvtafr==7 /*2002 elections*/
replace seat_s=0 if prtvtfr==7 | prtvtafr==7
replace in_p=0 if prtvtfr==7 | prtvtafr==7
replace in_c=0 if prtvtfr==7 | prtvtafr==7
replace ever_in_p=0 if prtvtfr==7 | prtvtafr==7
replace ever_in_c=0 if prtvtfr==7 | prtvtafr==7

* FR FN
replace vote_s=11.34 if prtvtfr==3 | prtvtafr==3
replace seat_s=0 if prtvtfr==3 | prtvtafr==3
replace in_p=0 if prtvtfr==3 | prtvtafr==3
replace in_c=0 if prtvtfr==3 | prtvtafr==3
replace ever_in_p=1 if prtvtfr==3 | prtvtafr==3
replace ever_in_c=0 if prtvtfr==3 | prtvtafr==3
replace epvote=5.7 if prtvtfr==3 | prtvtafr==3

replace vote_s=4.3 if prtvtbfr==2 /*2007 elections*/
replace seat_s=0 if prtvtbfr==2
replace in_p=0 if prtvtbfr==2
replace in_c=0 if prtvtbfr==2
replace ever_in_p=1 if prtvtbfr==2
replace ever_in_c=0 if prtvtbfr==2
replace epvote=6.34 if prtvtbfr==2

replace vote_s=13.6 if prtvtcfr==2 /*2012 elections*/
replace seat_s=0 if prtvtcfr==2
replace in_p=0 if prtvtcfr==2
replace in_c=0 if prtvtcfr==2
replace ever_in_p=1 if prtvtcfr==2
replace ever_in_c=0 if prtvtcfr==2
replace epvote=24.9 if prtvtcfr==2

replace vote_s=21.3 if prtvtdfr==11 /*2017 elections*/
replace epvote=23.34 if prtvtdfr==11

* DE AFD
replace vote_s=4.7 if prtvede2==6 & year<2018 /*2013 elections*/
replace seat_s=0 if prtvede2==6 & year<2018
replace in_p=0 if prtvede2==6
replace in_c=0 if prtvede2==6
replace ever_in_p=0 if prtvede2==6
replace ever_in_c=0 if prtvede2==6
replace epvote=7.1 if prtvede2==6 & year<2018

replace vote_s=12.6 if prtvede2==6 & year==2018 /*2017 elections*/
replace seat_s=13 if prtvede2==6 & year==2018 
replace epvote=11 if prtvede2==6 & year==2018 

* DE NPD
replace vote_s=.4 if prtvade2==7
replace seat_s=0 if prtvade2==7
replace in_p=0 if prtvade2==7
replace in_c=0 if prtvade2==7
replace ever_in_p=0 if prtvade2==7
replace ever_in_c=0 if prtvade2==7

replace vote_s=1.6 if prtvbde2==7
replace seat_s=0 if prtvbde2==7
replace in_p=0 if prtvbde2==7
replace in_c=0 if prtvbde2==7
replace ever_in_p=0 if prtvbde2==7
replace ever_in_c=0 if prtvbde2==7

replace vote_s=1.5 if prtvcde2==7
replace seat_s=0 if prtvcde2==7
replace in_p=0 if prtvcde2==7
replace in_c=0 if prtvcde2==7
replace ever_in_p=0 if prtvcde2==7
replace ever_in_c=0 if prtvcde2==7

replace vote_s=1.5 if prtvdde2==7
replace seat_s=0 if prtvdde2==7
replace in_p=0 if prtvdde2==7
replace in_c=0 if prtvdde2==7
replace ever_in_p=0 if prtvdde2==7
replace ever_in_c=0 if prtvdde2==7

replace vote_s=1.3 if prtvede2==8
replace seat_s=0 if prtvede2==8
replace in_p=0 if prtvede2==8
replace in_c=0 if prtvede2==8
replace ever_in_p=0 if prtvede2==8
replace ever_in_c=0 if prtvede2==8

* GR GD
replace vote_s=.3 if prtvtcgr==10
replace seat_s=0 if prtvtcgr==10
replace in_p=0 if prtvtcgr==10
replace in_c=0 if prtvtcgr==10
replace ever_in_p=0 if prtvtcgr==10
replace ever_in_c=0 if prtvtcgr==10

*GR LAOS
replace vote_s=2.2 if prtvtagr==6
replace seat_s=0 if prtvtagr==6
replace in_p=0 if prtvtagr==6
replace in_c=0 if prtvtagr==6
replace ever_in_p=0 if prtvtagr==6
replace ever_in_c=0 if prtvtagr==6
replace epvote=4.1 if prtvtagr==6

replace vote_s=3.8 if prtvtbgr==5
replace seat_s=3.33 if prtvtbgr==5
replace in_p=0 if prtvtbgr==5
replace in_c=0 if prtvtbgr==5
replace ever_in_p=0 if prtvtbgr==5
replace ever_in_c=0 if prtvtbgr==5
replace epvote=7.14 if prtvtbgr==5

replace vote_s=5.6 if prtvtcgr==4
replace seat_s=3.66 if prtvtcgr==4
replace in_p=1 if prtvtcgr==4
replace in_c=0 if prtvtcgr==4
replace ever_in_p=1 if prtvtcgr==4
replace ever_in_c=0 if prtvtcgr==4
replace epvote=7.14 if prtvtcgr==4
* IS LP
replace vote_s=7.4 if prtvtis==2 /*2003 elections*/
replace seat_s=6.3 if prtvtis==2
replace in_p=1 if prtvtis==2
replace in_c=0 if prtvtis==2
replace ever_in_p=1 if prtvtis==2
replace ever_in_c=0 if prtvtis==2

replace vote_s=2.2 if prtvtais==5 /*2009 elections*/
replace seat_s=0 if prtvtais==5
replace in_p=1 if prtvtais==5
replace in_c=0 if prtvtais==5
replace ever_in_p=1 if prtvtais==5
replace ever_in_c=0 if prtvtais==5

* IT AN
replace vote_s=12 if prtvtit==9 & year==2002
replace seat_s=15.7 if prtvtit==9 & year==2002
replace in_p=1 if prtvtit==9 & year==2002
replace in_c=0 if prtvtit==9 & year==2002
replace ever_in_p=1 if prtvtit==9 & year==2002
replace ever_in_c=0 if prtvtit==9 & year==2002
replace epvote=10.3 if prtvtit==9 & year==2002

replace vote_s=12 if prtvtait==9
replace seat_s=15.7 if prtvtait==9
replace in_p=1 if prtvtait==9
replace in_c=0 if prtvtait==9
replace ever_in_p=1 if prtvtait==9
replace ever_in_c=0 if prtvtait==9
replace epvote=10.3 if prtvtait==9
* IT LN
replace vote_s=3.9 if prtvtit==11 & year==2002
replace seat_s=4.76 if prtvtit==11 & year==2002
replace in_p=1 if prtvtit==11 & year==2002
replace in_c=0 if prtvtit==11 & year==2002
replace ever_in_p=1 if prtvtit==11 & year==2002
replace ever_in_c=1 if prtvtit==11 & year==2002
replace epvote=4.49 if prtvtit==11 & year==2002

replace vote_s=3.9 if prtvtait==11
replace seat_s=4.76 if prtvtait==11
replace in_p=1 if prtvtait==11
replace in_c=0 if prtvtait==11
replace ever_in_p=1 if prtvtait==11
replace ever_in_c=1 if prtvtait==11
replace epvote=4.49 if prtvtait==11

replace vote_s=8.3 if prtvtbit==9
replace seat_s=9.5 if prtvtbit==9
replace in_p=1 if prtvtbit==9
replace in_c=0 if prtvtbit==9
replace ever_in_p=1 if prtvtbit==9
replace ever_in_c=1 if prtvtbit==9
replace epvote=10.2 if prtvtbit==9

replace vote_s=17.39 if prtvtcit==9
replace seat_s=20.1 if prtvtcit==9
replace epvote=34.26 if prtvtcit==9
* NL LPF
replace vote_s=17 if prtvtnl==4
replace seat_s=17.3 if prtvtnl==4
replace in_p=0 if prtvtnl==4
replace in_c=0 if prtvtnl==4
replace ever_in_p=1 if prtvtnl==4
replace ever_in_c=1 if prtvtnl==4
replace epvote=0 if prtvtnl==4

replace vote_s=5.7 if prtvtanl==4
replace seat_s=5.3 if prtvtanl==4
replace in_p=1 if prtvtanl==4
replace in_c=1 if prtvtanl==4
replace ever_in_p=1 if prtvtanl==4
replace ever_in_c=1 if prtvtanl==4
replace epvote=0  if prtvtanl==4

replace vote_s=0.2 if prtvtbnl==4
replace seat_s=0 if prtvtbnl==4
replace in_p=0 if prtvtbnl==4
replace in_c=0 if prtvtbnl==4
replace ever_in_p=1 if prtvtbnl==4
replace ever_in_c=1 if prtvtbnl==4

replace vote_s=0.2 if prtvtcnl==4
replace seat_s=0 if prtvtcnl==4
replace in_p=0 if prtvtcnl==4
replace in_c=0 if prtvtcnl==4
replace ever_in_p=1 if prtvtcnl==4
replace ever_in_c=1 if prtvtcnl==4

* NL PVV
replace vote_s=5.89 if prtvtcnl==11
replace seat_s=6 if prtvtcnl==11
replace in_p=0 if prtvtcnl==11
replace in_c=0 if prtvtcnl==11
replace ever_in_p=0 if prtvtcnl==11
replace ever_in_c=0 if prtvtcnl==11
replace epvote=0 if prtvtcnl==11

replace vote_s=15.45 if prtvtdnl==3
replace seat_s=16 if prtvtdnl==3
replace in_p=1 if prtvtdnl==3
replace in_c=1 if prtvtdnl==3
replace ever_in_p=1 if prtvtdnl==3
replace ever_in_c=0 if prtvtdnl==3
replace epvote=16.97 if prtvtdnl==3

replace vote_s=10.08 if prtvtenl==3
replace seat_s=10 if prtvtenl==3
replace in_p=1 if prtvtenl==3
replace in_c=1 if prtvtenl==3
replace ever_in_p=1 if prtvtenl==3
replace ever_in_c=1 if prtvtenl==3
replace epvote=13.3 if prtvtenl==3

replace vote_s=10.08 if prtvtfnl==3
replace seat_s=16 if prtvtfnl==3
replace in_p=1 if prtvtfnl==3
replace in_c=1 if prtvtfnl==3
replace ever_in_p=1 if prtvtfnl==3
replace ever_in_c=1 if prtvtfnl==3
replace epvote=13.3 if prtvtfnl==3

replace vote_s=13 if prtvtgnl==3
replace seat_s=13 if prtvtgnl==3
replace epvote=3.53 if prtvtgnl==3

* NO FRP (progress party)
replace vote_s=14.6 if prtvtno==8 & year<2005
replace seat_s=15.75 if prtvtno==8 & year<2005
replace in_p=1 if prtvtno==8 & year<2005
replace in_c=0 if prtvtno==8 & year<2005
replace ever_in_p=1 if prtvtno==8 & year<2005
replace ever_in_c=0 if prtvtno==8 & year<2005
replace epvote=14.6 if prtvtno==8 & year<2005

replace vote_s=22.1 if prtvtno==8 & year>2005
replace seat_s=22.48 if prtvtno==8 & year>2005
replace in_p=1 if prtvtno==8 & year>2005
replace in_c=0 if prtvtno==8 & year>2005
replace ever_in_p=1 if prtvtno==8 & year>2005
replace ever_in_c=0 if prtvtno==8 & year>2005
replace epvote=22.1 if prtvtno==8 & year>2005

replace vote_s=22.9 if prtvtano==8
replace seat_s=24.26 if prtvtano==8
replace in_p=1 if prtvtano==8
replace in_c=0 if prtvtano==8
replace ever_in_p=1 if prtvtano==8
replace ever_in_c=0 if prtvtano==8
replace epvote=22.9 if prtvtano==8

replace vote_s=16.3 if prtvtbno==8 &year==2014
replace seat_s=17.16 if prtvtbno==8 &year==2014
replace in_p=1 if prtvtbno==8 &year==2014
replace in_c=1 if prtvtbno==8 &year==2014
replace ever_in_p=1 if prtvtbno==8 &year==2014
replace ever_in_c=1 if prtvtbno==8 &year==2014
replace epvote=16.3 if prtvtbno==8 &year==2014

replace vote_s=16.3 if prtvtbno==8 &year==2016
replace seat_s=17.16 if prtvtbno==8 &year==2016
replace in_p=1 if prtvtbno==8 &year==2016
replace in_c=1 if prtvtbno==8 &year==2016
replace ever_in_p=1 if prtvtbno==8 &year==2016
replace ever_in_c=1 if prtvtbno==8 &year==2016
replace vote_s=15.2 if prtvtbno==8 &year==2018
replace seat_s=16 if prtvtbno==8 &year==2018
replace epvote=16.3 if prtvtbno==8 &year==2016


* PT PNR
replace vote_s=.16 if prtvtapt==8
replace seat_s=0 if prtvtapt==8
replace in_p=0 if prtvtapt==8
replace in_c=0 if prtvtapt==8
replace ever_in_p=0 if prtvtapt==8
replace ever_in_c=0 if prtvtapt==8

replace vote_s=.2 if prtvtbpt==8 & year==2010
replace seat_s=0 if prtvtbpt==8 & year==2010
replace in_p=0 if prtvtbpt==8 & year==2010
replace in_c=0 if prtvtbpt==8 & year==2010
replace ever_in_p=0 if prtvtbpt==8 & year==2010
replace ever_in_c=0 if prtvtbpt==8 & year==2010

replace vote_s=.31 if prtvtbpt==8 & year>2010
replace seat_s=0 if prtvtbpt==8 & year>2010
replace in_p=0 if prtvtbpt==8 & year>2010
replace in_c=0 if prtvtbpt==8 & year>2010
replace ever_in_p=0 if prtvtbpt==8 & year>2010
replace ever_in_c=0 if prtvtbpt==8 & year>2010

* SE SvD
replace vote_s=5.7 if prtvtase==10
replace seat_s=5.73 if prtvtase==10
replace in_p=1 if prtvtase==10
replace in_c=0 if prtvtase==10
replace ever_in_p=1 if prtvtase==10
replace ever_in_c=0 if prtvtase==10
replace epvote=3.27 if prtvtase==10

replace vote_s=5.7 if prtvtbse==10 & year==2012
replace seat_s=0 if prtvtbse==10 & year==2012
replace in_p=1 if prtvtbse==10 & year==2012
replace in_c=0 if prtvtbse==10 & year==2012
replace ever_in_p=1 if prtvtbse==10 & year==2012
replace ever_in_c=0 if prtvtbse==10 & year==2012
replace epvote=3.27 if prtvtbse==10 & year==2012

replace vote_s=12.9 if prtvtbse==10 & year==2014
replace seat_s=14 if prtvtbse==10 & year==2014
replace in_p=1 if prtvtbse==10 & year==2014
replace in_c=0 if prtvtbse==10 & year==2014
replace ever_in_p=1 if prtvtbse==10 & year==2014
replace ever_in_c=0 if prtvtbse==10 & year==2014
replace vote_s=17.5 if prtvtcse==9
replace seat_s=18 if prtvtcse==9
replace epvote=9.7 if prtvtbse==10 & year==2014
replace epvote=15.34 if prtvtcse==9
* CH SVP
replace vote_s=22.5 if prtvtch==4 & year==2002
replace seat_s=20 if prtvtch==4 & year==2002
replace in_p=1 if prtvtch==4 & year==2002
replace in_c=1 if prtvtch==4 & year==2002
replace ever_in_p=1 if prtvtch==4 & year==2002
replace ever_in_c=1 if prtvtch==4 & year==2002

replace vote_s=26.6 if prtvtch==4 & year==2004
replace seat_s=27.5 if prtvtch==4 & year==2004
replace in_p=1 if prtvtch==4 & year==2004
replace in_c=1 if prtvtch==4 & year==2004
replace ever_in_p=1 if prtvtch==4 & year==2004
replace ever_in_c=1 if prtvtch==4 & year==2004

replace vote_s=26.6 if prtvtach==4 
replace seat_s=27.5 if prtvtach==4 
replace in_p=1 if prtvtach==4 
replace in_c=1 if prtvtach==4 
replace ever_in_p=1 if prtvtach==4 
replace ever_in_c=1 if prtvtach==4 

replace vote_s=28.9 if prtvtbch==4 
replace seat_s=31 if prtvtbch==4 
replace in_p=1 if prtvtbch==4 
replace in_c=1 if prtvtbch==4 
replace ever_in_p=1 if prtvtbch==4 
replace ever_in_c=1 if prtvtbch==4 

replace vote_s=28.9 if prtvtcch==4 
replace seat_s=31 if prtvtcch==4 
replace in_p=1 if prtvtcch==4 
replace in_c=1 if prtvtcch==4 
replace ever_in_p=1 if prtvtcch==4 
replace ever_in_c=1 if prtvtcch==4 

replace vote_s=26.6 if prtvtdch==1
replace seat_s=27 if prtvtdch==1
replace in_p=1 if prtvtdch==1
replace in_c=1 if prtvtdch==1 
replace ever_in_p=1 if prtvtdch==1
replace ever_in_c=1 if prtvtdch==1 

replace vote_s=26.6 if prtvtech==1
replace seat_s=27 if prtvtech==1
replace in_p=1 if prtvtech==1
replace in_c=1 if prtvtech==1 
replace ever_in_p=1 if prtvtech==1
replace ever_in_c=1 if prtvtech==1 

replace vote_s=29.4 if prtvtfch==1
replace seat_s=32.5 if prtvtfch==1
replace in_p=1 if prtvtfch==1
replace in_c=1 if prtvtfch==1 
replace ever_in_p=1 if prtvtfch==1
replace ever_in_c=1 if prtvtfch==1 

replace vote_s=29.4 if prtvtgch==1
replace seat_s=32.5 if prtvtgch==1

* UK BNP
replace vote_s=.7 if prtvtagb==7
replace seat_s=0 if prtvtagb==7
replace in_p=0 if prtvtagb==7
replace in_c=0 if prtvtagb==7
replace ever_in_p=0 if prtvtagb==7
replace ever_in_c=0 if prtvtagb==7

* UK UKIP
replace vote_s=2.2 if prtvtagb==8
replace seat_s=0 if prtvtagb==8
replace in_p=0 if prtvtagb==8
replace in_c=0 if prtvtagb==8
replace ever_in_p=0 if prtvtagb==8
replace ever_in_c=0 if prtvtagb==8
replace epvote=16.1 if prtvtagb==8

replace vote_s=3.1 if prtvtbgb==7 & year==2014
replace seat_s=0 if prtvtbgb==7& year==2014
replace in_p=0 if prtvtbgb==7& year==2014
replace in_c=0 if prtvtbgb==7& year==2014
replace ever_in_p=0 if prtvtbgb==7& year==2014
replace ever_in_c=0 if prtvtbgb==7& year==2014
replace epvote=27.5 if prtvtbgb==7& year==2014

replace vote_s=12.6 if prtvtbgb==7 & year==2016
replace seat_s=0.15 if prtvtbgb==7& year==2016
replace in_p=1 if prtvtbgb==7& year==2016
replace in_c=0 if prtvtbgb==7& year==2016
replace ever_in_p=0 if prtvtbgb==7& year==2016
replace ever_in_c=0 if prtvtbgb==7& year==2016
replace epvote=27.5 if prtvtbgb==7& year==2016
		
replace vote_s=1.8 if prtvtcgb==7
replace seat_s=0 if prtvtcgb==7
replace epvote=3.3 	if prtvtcgb==7	
by cntry year, sort: egen votshare =max(vote_share)
by cntry year, sort: egen seatshare =max(seat_share)
by cntry year, sort: egen epvoteshare=max(epvote)
recode votshare  (. =0)
recode seatshare (. =0)
recode epvoteshare (. =0)
replace votshare=votshare/100
replace seatshare=seatshare/100
replace epvoteshare=epvoteshare/100		
/* (1)
* =====================================
  =    L-R LOCATION OF MAIN LEFT PARTY 
  =    IN EVERY CNTRYEAR (CHES DATA)*
* =====================================

LIST OF MAIN SD PARTIES PER COUNTRY:
AT-SPO
BE-SOCIALIST PARTY(PS)
DE-SPD
DK-SOCIAL DEMOCRATS (SD)
ES-PSOE
FI-SDP
FR-PS
GB-LABOUR
GR-PASOK
IE-LABOUR
IT-DEMOCRATS OF THE LEFT (DS)
LU-LSAP
NL-PvdA
PT-SOCIALIST PARTY (PS)
SE-SAP 
CH -SP/PS
NO - LABOUR/SV */
* for each cntry-year we apply lrecon of either the same year or the preceding CHES wave (in cases where CHES was not run that year).  
gen lreconL=.

replace lreconL=3.44 if cntry=="AT" & year==2002 /*CHES02*/
replace lreconL=3.44 if cntry=="AT" & year==2004 /*CHES02*/
replace lreconL=2.83 if cntry=="AT" & year==2006 /*CHES06*/
replace lreconL=2.83 if cntry=="AT" & year==2008 /*CHES06*/
replace lreconL=2.64 if cntry=="AT" & year==2010 /*CHES10*/
replace lreconL=2.64 if cntry=="AT" & year==2012 /*CHES10*/
replace lreconL=2.8  if cntry=="AT" & year==2014 /*CHES14*/
replace lreconL=2.8  if cntry=="AT" & year==2016 /*CHES14*/
replace lreconL=2.8  if cntry=="AT" & year==2018 /*CHES14*/
replace lreconL=3.6  if cntry=="AT" & year==2020 /*CHES19*/

replace lreconL=2.5  if cntry=="BE" & year==2002 /*CHES02*/
replace lreconL=2.5  if cntry=="BE" & year==2004 /*CHES02*/
replace lreconL=3.17 if cntry=="BE" & year==2006 /*CHES06*/
replace lreconL=3.17 if cntry=="BE" & year==2008 /*CHES06*/
replace lreconL=2.57 if cntry=="BE" & year==2010 /*CHES10*/
replace lreconL=2.57 if cntry=="BE" & year==2012 /*CHES10*/
replace lreconL=2.4  if cntry=="BE" & year==2014 /*CHES14*/
replace lreconL=2.4  if cntry=="BE" & year==2016 /*CHES14*/
replace lreconL=2.4  if cntry=="BE" & year==2018 /*CHES14*/
replace lreconL=2.25 if cntry=="BE" & year==2020 /*CHES19*/

replace lreconL=3.57 if cntry=="DE" & year==2002 /*CHES02*/
replace lreconL=3.57 if cntry=="DE" & year==2004 /*CHES02*/
replace lreconL=3.36 if cntry=="DE" & year==2006 /*CHES06*/
replace lreconL=3.36 if cntry=="DE" & year==2008 /*CHES06*/
replace lreconL=3    if cntry=="DE" & year==2010 /*CHES10*/ 
replace lreconL=3    if cntry=="DE" & year==2012 /*CHES10*/
replace lreconL=3.5  if cntry=="DE" & year==2014 /*CHES14*/ 
replace lreconL=3.5  if cntry=="DE" & year==2016 /*CHES14*/
replace lreconL=3.5  if cntry=="DE" & year==2018 /*CHES14*/ 
replace lreconL=3.71 if cntry=="DE" & year==2020 /*CHES19*/

replace lreconL=2    if cntry=="DK" & year==2002 /*CHES02*/
replace lreconL=2    if cntry=="DK" & year==2004 /*CHES02*/
replace lreconL=2.25 if cntry=="DK" & year==2006 /*CHES06*/
replace lreconL=2.25 if cntry=="DK" & year==2008 /*CHES06*/
replace lreconL=2.27 if cntry=="DK" & year==2010 /*CHES10*/
replace lreconL=2.27 if cntry=="DK" & year==2012 /*CHES10*/
replace lreconL=2.3  if cntry=="DK" & year==2014 /*CHES14*/
replace lreconL=2.3  if cntry=="DK" & year==2016 /*CHES14*/
replace lreconL=.    if cntry=="DK" & year==2018 /*CHES14*/
replace lreconL=.    if cntry=="DK" & year==2020 /*CHES19*/

replace lreconL=4.23 if cntry=="ES" & year==2002 /*CHES02*/
replace lreconL=4.23 if cntry=="ES" & year==2004 /*CHES02*/
replace lreconL=3.92 if cntry=="ES" & year==2006 /*CHES06*/
replace lreconL=3.92 if cntry=="ES" & year==2008 /*CHES06*/
replace lreconL=3.5  if cntry=="ES" & year==2010 /*CHES10*/
replace lreconL=3.5  if cntry=="ES" & year==2012 /*CHES10*/
replace lreconL=4.11 if cntry=="ES" & year==2014 /*CHES14*/
replace lreconL=4.11 if cntry=="ES" & year==2016 /*CHES14*/
replace lreconL=4.11 if cntry=="ES" & year==2018 /*CHES14*/
replace lreconL=3.8  if cntry=="ES" & year==2020 /*CHES19*/

replace lreconL=3.89 if cntry=="FI" & year==2002 /*CHES02*/
replace lreconL=3.89 if cntry=="FI" & year==2004 /*CHES02*/
replace lreconL=3    if cntry=="FI" & year==2006 /*CHES06*/
replace lreconL=3    if cntry=="FI" & year==2008 /*CHES06*/
replace lreconL=3.6  if cntry=="FI" & year==2010 /*CHES10*/
replace lreconL=3.6  if cntry=="FI" & year==2012 /*CHES10*/
replace lreconL=3.44 if cntry=="FI" & year==2014 /*CHES14*/
replace lreconL=3.44 if cntry=="FI" & year==2016 /*CHES14*/
replace lreconL=3.44 if cntry=="FI" & year==2018 /*CHES14*/
replace lreconL=3.21 if cntry=="FI" & year==2020 /*CHES19*/

replace lreconL=4.08 if cntry=="FR" & year==2002 /*CHES02*/
replace lreconL=4.08 if cntry=="FR" & year==2004 /*CHES02*/
replace lreconL=2.13 if cntry=="FR" & year==2006 /*CHES06*/
replace lreconL=2.13 if cntry=="FR" & year==2008 /*CHES06*/
replace lreconL=2.44 if cntry=="FR" & year==2010 /*CHES10*/
replace lreconL=2.44 if cntry=="FR" & year==2012 /*CHES10*/
replace lreconL=3.83 if cntry=="FR" & year==2014 /*CHES14*/
replace lreconL=3.83 if cntry=="FR" & year==2016 /*CHES14*/
replace lreconL=3.83 if cntry=="FR" & year==2018 /*CHES14*/
replace lreconL=3.12 if cntry=="FR" & year==2020 /*CHES19*/

replace lreconL=5.28 if cntry=="GB" & year==2002 /*CHES02*/
replace lreconL=5.28 if cntry=="GB" & year==2004 /*CHES02*/
replace lreconL=4.44 if cntry=="GB" & year==2006 /*CHES06*/
replace lreconL=4.44 if cntry=="GB" & year==2008 /*CHES06*/
replace lreconL=4    if cntry=="GB" & year==2010 /*CHES10*/
replace lreconL=4    if cntry=="GB" & year==2012 /*CHES10*/
replace lreconL=3.86 if cntry=="GB" & year==2014 /*CHES14*/
replace lreconL=3.86 if cntry=="GB" & year==2016 /*CHES14*/
replace lreconL=3.86 if cntry=="GB" & year==2018 /*CHES14*/
replace lreconL=1.94 if cntry=="GB" & year==2020 /*CHES19*/

replace lreconL=4.64 if cntry=="GR" & year==2002 /*CHES02*/
replace lreconL=4.64 if cntry=="GR" & year==2004 /*CHES02*/
replace lreconL=4.22 if cntry=="GR" & year==2006 /*CHES06*/
replace lreconL=4.22 if cntry=="GR" & year==2008 /*CHES06*/
replace lreconL=5.64 if cntry=="GR" & year==2010 /*CHES10*/
replace lreconL=5.64 if cntry=="GR" & year==2012 /*CHES10*/
replace lreconL=5.44 if cntry=="GR" & year==2014 /*CHES14*/
replace lreconL=5.44 if cntry=="GR" & year==2016 /*CHES14*/
replace lreconL=5.44 if cntry=="GR" & year==2018 /*CHES14*/
replace lreconL=4.22 if cntry=="GR" & year==2020 /*CHES19*/

replace lreconL=3    if cntry=="IE" & year==2002 /*CHES02*/
replace lreconL=3    if cntry=="IE" & year==2004 /*CHES02*/
replace lreconL=3.8  if cntry=="IE" & year==2006 /*CHES06*/
replace lreconL=3.8  if cntry=="IE" & year==2008 /*CHES06*/
replace lreconL=3.5  if cntry=="IE" & year==2010 /*CHES10*/
replace lreconL=3.5  if cntry=="IE" & year==2012 /*CHES10*/
replace lreconL=4.13 if cntry=="IE" & year==2014 /*CHES14*/
replace lreconL=4.13 if cntry=="IE" & year==2016 /*CHES14*/
replace lreconL=4.13 if cntry=="IE" & year==2018 /*CHES14*/
replace lreconL=3.57 if cntry=="IE" & year==2020 /*CHES19*/

replace lreconL=3.42 if cntry=="IT" & year==2002 /*CHES02*/
replace lreconL=3.42 if cntry=="IT" & year==2004 /*CHES02*/
replace lreconL=3    if cntry=="IT" & year==2006 /*CHES06*/
replace lreconL=3    if cntry=="IT" & year==2008 /*CHES06*/
replace lreconL=.    if cntry=="IT" & year==2010 /*CHES10*/
replace lreconL=.    if cntry=="IT" & year==2012 /*CHES10*/
replace lreconL=.    if cntry=="IT" & year==2014 /*CHES14*/
replace lreconL=.    if cntry=="IT" & year==2016 /*CHES14*/
replace lreconL=.    if cntry=="IT" & year==2018 /*CHES14*/
replace lreconL=.    if cntry=="IT" & year==2020 /*CHES19*/

replace lreconL=4.5  if cntry=="LU" & year==2014 /*CHES14*/
replace lreconL=4.5  if cntry=="LU" & year==2016 /*CHES14*/
replace lreconL=4.5  if cntry=="LU" & year==2018 /*CHES14*/
replace lreconL=4    if cntry=="LU" & year==2020 /*CHES19*/

replace lreconL=1.5  if cntry=="NO" & year==2014 /*CHES14*/
replace lreconL=1.5  if cntry=="NO" & year==2016 /*CHES14*/
replace lreconL=1.5  if cntry=="NO" & year==2018 /*CHES14*/
replace lreconL=1.5  if cntry=="NO" & year==2020 /*CHES19*/

replace lreconL=2    if cntry=="CH" & year==2014 /*CHES14*/
replace lreconL=2    if cntry=="CH" & year==2016 /*CHES14*/
replace lreconL=2    if cntry=="CH" & year==2018 /*CHES14*/
replace lreconL=1.63 if cntry=="CH" & year==2020 /*CHES19*/

replace lreconL=3.78  if cntry=="NL" & year==2002 /*CHES02*/
replace lreconL=3.78  if cntry=="NL" & year==2004 /*CHES02*/
replace lreconL=3.56  if cntry=="NL" & year==2006 /*CHES06*/
replace lreconL=3.56  if cntry=="NL" & year==2008 /*CHES06*/
replace lreconL=3.57  if cntry=="NL" & year==2010 /*CHES10*/
replace lreconL=3.57  if cntry=="NL" & year==2012 /*CHES10*/
replace lreconL=3.22  if cntry=="NL" & year==2014 /*CHES14*/
replace lreconL=3.22  if cntry=="NL" & year==2016 /*CHES14*/
replace lreconL=3.22  if cntry=="NL" & year==2018 /*CHES14*/
replace lreconL=3.61  if cntry=="NL" & year==2020 /*CHES19*/

replace lreconL=3.71  if cntry=="SE" & year==2002 /*CHES02*/
replace lreconL=3.71  if cntry=="SE" & year==2004 /*CHES02*/
replace lreconL=3.22  if cntry=="SE" & year==2006 /*CHES06*/
replace lreconL=3.22  if cntry=="SE" & year==2008 /*CHES06*/
replace lreconL=3.43  if cntry=="SE" & year==2010 /*CHES10*/
replace lreconL=3.43  if cntry=="SE" & year==2012 /*CHES10*/
replace lreconL=3.43  if cntry=="SE" & year==2014 /*CHES14*/
replace lreconL=3.43  if cntry=="SE" & year==2016 /*CHES14*/
replace lreconL=3.43  if cntry=="SE" & year==2018 /*CHES14*/
replace lreconL=4.11  if cntry=="SE" & year==2020 /*CHES19*/

replace lreconL=3.86  if cntry=="PT" & year==2002 /*CHES02*/
replace lreconL=3.86  if cntry=="PT" & year==2004 /*CHES02*/
replace lreconL=4.8   if cntry=="PT" & year==2006 /*CHES06*/
replace lreconL=4.8   if cntry=="PT" & year==2008 /*CHES06*/
replace lreconL=4     if cntry=="PT" & year==2010 /*CHES10*/
replace lreconL=4     if cntry=="PT" & year==2012 /*CHES10*/
replace lreconL=4.67  if cntry=="PT" & year==2014 /*CHES14*/
replace lreconL=4.67  if cntry=="PT" & year==2016 /*CHES14*/
replace lreconL=4.67  if cntry=="PT" & year==2018 /*CHES14*/
replace lreconL=4     if cntry=="PT" & year==2020 /*CHES19*/

* =====================================
* =    L-R LOCATION OF MAIN RR PARTY 
*  =    IN EVERY CNTRYEAR (CHES DATA)*
* =====================================
/*
LIST OF MAIN RR PARTIES PER COUNTRY:
AT-FPO
BE-National Front, Vlaams Bloc
DK-Danish People's Party (DPP)
FI-True Finns
FR-Front National
GR-LAOS
IT-Lega Nord, National Alliance
NL-Pim Fortuyn List (02-08) , Freedom Party (10-12)
NO-Progress Party
IS - Liberal Party(04); Liberal Party Citizens' Movement(12) 
SE-Sweden Democrats (10-12)
GB- UKIP */

gen lreconR=.

replace lreconR=7.31 if cntry=="AT" & year==2002 /*CHES02*/
replace lreconR=7.31 if cntry=="AT" & year==2004 /*CHES02*/
replace lreconR=4.83 if cntry=="AT" & year==2006 /*CHES06*/
replace lreconR=4.83 if cntry=="AT" & year==2008 /*CHES06*/
replace lreconR=5    if cntry=="AT" & year==2010 /*CHES10*/
replace lreconR=5    if cntry=="AT" & year==2012 /*CHES10*/
replace lreconR=5.5  if cntry=="AT" & year==2014 /*CHES14*/
replace lreconR=5.5  if cntry=="AT" & year==2016 /*CHES14*/
replace lreconR=5.5  if cntry=="AT" & year==2018 /*CHES14*/
replace lreconR=6.5  if cntry=="AT" & year==2020 /*CHES19*/

replace lreconR=7.9  if cntry=="BE" & year==2002 /*CHES02*/
replace lreconR=7.9  if cntry=="BE" & year==2004 /*CHES02*/
replace lreconR=7.13 if cntry=="BE" & year==2006 /*CHES06*/
replace lreconR=7.13 if cntry=="BE" & year==2008 /*CHES06*/
replace lreconR=7.93 if cntry=="BE" & year==2010 /*CHES10*/
replace lreconR=7.93 if cntry=="BE" & year==2012 /*CHES10*/
replace lreconR=5.5  if cntry=="BE" & year==2014 /*CHES14*/
replace lreconR=5.5  if cntry=="BE" & year==2016 /*CHES14*/
replace lreconR=5.5  if cntry=="BE" & year==2018 /*CHES14*/
replace lreconR=5    if cntry=="BE" & year==2020 /*CHES19*/

replace lreconR=6.08 if cntry=="DK" & year==2002 /*CHES02*/
replace lreconR=6.08 if cntry=="DK" & year==2004 /*CHES02*/
replace lreconR=4.75 if cntry=="DK" & year==2006 /*CHES06*/
replace lreconR=4.75 if cntry=="DK" & year==2008 /*CHES06*/
replace lreconR=5.45 if cntry=="DK" & year==2010 /*CHES10*/
replace lreconR=5.45 if cntry=="DK" & year==2012 /*CHES10*/
replace lreconR=4.5  if cntry=="DK" & year==2014 /*CHES14*/
replace lreconR=4.5  if cntry=="DK" & year==2016 /*CHES14*/
replace lreconR=4.5  if cntry=="DK" & year==2018 /*CHES14*/
replace lreconR=4.43 if cntry=="DK" & year==2020 /*CHES19*/

replace lreconR=.    if cntry=="FI" & year==2002 /*CHES99*/
replace lreconR=.    if cntry=="FI" & year==2004 /*CHES99*/
replace lreconR=4.82 if cntry=="FI" & year==2006 /*CHES06*/
replace lreconR=4.82 if cntry=="FI" & year==2008 /*CHES06*/
replace lreconR=4.3  if cntry=="FI" & year==2010 /*CHES10*/
replace lreconR=4.3  if cntry=="FI" & year==2012 /*CHES10*/
replace lreconR=4.11 if cntry=="FI" & year==2014 /*CHES14*/
replace lreconR=4.11 if cntry=="FI" & year==2016 /*CHES14*/
replace lreconR=4.11 if cntry=="FI" & year==2018 /*CHES14*/
replace lreconR=6.43 if cntry=="FI" & year==2020 /*CHES19*/

replace lreconR=6    if cntry=="FR" & year==2002 /*CHES02*/
replace lreconR=6    if cntry=="FR" & year==2004 /*CHES02*/
replace lreconR=6.63 if cntry=="FR" & year==2006 /*CHES06*/
replace lreconR=6.63 if cntry=="FR" & year==2008 /*CHES10*/
replace lreconR=6.5  if cntry=="FR" & year==2010 /*CHES10*/
replace lreconR=6.5  if cntry=="FR" & year==2012 /*CHES10*/
replace lreconR=5.9  if cntry=="FR" & year==2014 /*CHES14*/
replace lreconR=5.9  if cntry=="FR" & year==2016 /*CHES14*/
replace lreconR=5.9  if cntry=="FR" & year==2018 /*CHES14*/
replace lreconR=6.87 if cntry=="FR" & year==2020 /*RN,CHES19*/

replace lreconR=.    if cntry=="GR" & year==2002 /*CHES02, laos party*/
replace lreconR=.    if cntry=="GR" & year==2004 /*CHES02*/
replace lreconR=5.33 if cntry=="GR" & year==2006 /*CHES06*/
replace lreconR=5.33 if cntry=="GR" & year==2008 /*CHES10*/
replace lreconR=5.9  if cntry=="GR" & year==2010 /*CHES10*/
replace lreconR=5.9  if cntry=="GR" & year==2012 /*CHES10*/
replace lreconR=5.33 if cntry=="GR" & year==2014 /*CHES14*/
replace lreconR=5.33 if cntry=="GR" & year==2016 /*CHES14*/
replace lreconR=5.33 if cntry=="GR" & year==2018 /*CHES14*/
replace lreconR=4.37 if cntry=="GR" & year==2020 /*CHES19, el party*/

replace lreconR=7.28 if cntry=="IT" & year==2002 /*CHES02, LN*/
replace lreconR=7.28 if cntry=="IT" & year==2004 /*CHES02*/
replace lreconR=8.14 if cntry=="IT" & year==2006 /*CHES06*/
replace lreconR=8.14 if cntry=="IT" & year==2008 /*CHES*/
replace lreconR=7.33 if cntry=="IT" & year==2010 /*CHES10*/
replace lreconR=7.33 if cntry=="IT" & year==2012 /*CHES10*/
replace lreconR=7.28 if cntry=="IT" & year==2014 /*CHES14*/
replace lreconR=7.28 if cntry=="IT" & year==2016 /*CHES14*/
replace lreconR=7.28 if cntry=="IT" & year==2018 /*CHES14*/
replace lreconR=7.68 if cntry=="IT" & year==2020 /*CHES19*/

replace lreconR=8.11 if cntry=="NL" & year==2002 /*CHES02, LPF*/
replace lreconR=8.11 if cntry=="NL" & year==2004 /*CHES02, LPF*/
replace lreconR=8.29 if cntry=="NL" & year==2006 /*CHES06, PVV*/
replace lreconR=8.29 if cntry=="NL" & year==2008 /*CHES10, PVV*/
replace lreconR=5.23 if cntry=="NL" & year==2010 /*CHES10, PVV*/
replace lreconR=4.55 if cntry=="NL" & year==2014 /*CHES14, PVV*/
replace lreconR=4.55 if cntry=="NL" & year==2016 /*CHES14, PVV*/
replace lreconR=4.55 if cntry=="NL" & year==2018 /*CHES14, PVV*/
replace lreconR=6.46 if cntry=="NL" & year==2020 /*CHES19, PVV*/

replace lreconR=.    if cntry=="SE" & year==2002 /*CHES02*/
replace lreconR=.    if cntry=="SE" & year==2004 /*CHES02*/
replace lreconR=.    if cntry=="SE" & year==2006 /*CHES06*/
replace lreconR=.    if cntry=="SE" & year==2008 /*CHES10*/
replace lreconR=5.54 if cntry=="SE" & year==2010 /*CHES10*/
replace lreconR=5.54 if cntry=="SE" & year==2012 /*CHES10*/
replace lreconR=5.4  if cntry=="SE" & year==2014 /*CHES14*/
replace lreconR=5.4  if cntry=="SE" & year==2016 /*CHES14*/
replace lreconR=5.4  if cntry=="SE" & year==2018 /*CHES14*/
replace lreconR=5.59 if cntry=="SE" & year==2020 /*CHES19*/


replace lreconR=7.5 if cntry=="NO" & year==2014 /*FrP, CHES14, taken seperatly from the 2014 wave */
replace lreconR=7.5 if cntry=="NO" & year==2016 /*FrP,CHES14, taken seperatly from the 2014 wave */
replace lreconR=7.5 if cntry=="NO" & year==2018 /*FrP,CHES14, taken seperatly from the 2014 wave */
replace lreconR=7.9 if cntry=="NO" & year==2020 /*FrP,CHES19, taken seperatly from the 2014 wave */
replace lreconR=7.5 if cntry=="CH" & year==2014 /*SVP,CHES14, taken seperatly from the 2014 wave */
replace lreconR=7.5 if cntry=="CH" & year==2016 /*SVP,CHES14, taken seperatly from the 2014 wave */
replace lreconR=7.5 if cntry=="CH" & year==2018 /*SVP,CHES14, taken seperatly from the 2014 wave */
replace lreconR=8.18 if cntry=="CH" & year==2020 /*SVP,CHES14, taken seperatly from the 2014 wave */

replace lreconR=8.57 if cntry=="GB"& year==2016 /*CHES14*/

gen galtanL=. /*galtan values are applied for main left-wing parties*/
replace galtanL=3.38 if cntry=="AT" & year==2002 /*CHES02*/
replace galtanL=3.38 if cntry=="AT" & year==2004 /*CHES02*/
replace galtanL=3.5  if cntry=="AT" & year==2006 /*CHES06*/
replace galtanL=3.5  if cntry=="AT" & year==2008 /*CHES06*/
replace galtanL=3.93 if cntry=="AT" & year==2010 /*CHES10*/
replace galtanL=3.93 if cntry=="AT" & year==2012 /*CHES10*/
replace galtanL=4    if cntry=="AT" & year==2014 /*CHES14*/
replace galtanL=4    if cntry=="AT" & year==2016 /*CHES14*/
replace galtanL=4    if cntry=="AT" & year==2018 /*CHES14*/
replace galtanL=3.8  if cntry=="AT" & year==2020 /*CHES19*/

replace galtanL=4    if cntry=="BE" & year==2002 /*CHES02*/
replace galtanL=4    if cntry=="BE" & year==2004 /*CHES02*/
replace galtanL=2.83 if cntry=="BE" & year==2006 /*CHES06*/
replace galtanL=2.83 if cntry=="BE" & year==2008 /*CHES06*/
replace galtanL=2.86 if cntry=="BE" & year==2010 /*CHES10*/
replace galtanL=2.86 if cntry=="BE" & year==2012 /*CHES10*/
replace galtanL=3.4  if cntry=="BE" & year==2014 /*CHES14*/
replace galtanL=3.4  if cntry=="BE" & year==2016 /*CHES14*/
replace galtanL=3.4  if cntry=="BE" & year==2018 /*CHES14*/
replace galtanL=2.91 if cntry=="BE" & year==2020 /*CHES19*/

replace galtanL=4.57 if cntry=="DE" & year==2002 /*CHES02*/
replace galtanL=4.57 if cntry=="DE" & year==2004 /*CHES02*/
replace galtanL=4.45 if cntry=="DE" & year==2006 /*CHES06*/
replace galtanL=4.45 if cntry=="DE" & year==2008 /*CHES06*/
replace galtanL=4.5  if cntry=="DE" & year==2010 /*CHES10*/ 
replace galtanL=4.5  if cntry=="DE" & year==2012 /*CHES10*/
replace galtanL=4.15 if cntry=="DE" & year==2014 /*CHES14*/ 
replace galtanL=4.15 if cntry=="DE" & year==2016 /*CHES14*/
replace galtanL=4.15 if cntry=="DE" & year==2018 /*CHES14*/ 
replace galtanL=3.38 if cntry=="DE" & year==2020 /*CHES19*/

replace galtanL=4.38 if cntry=="DK" & year==2002 /*CHES02*/
replace galtanL=4.38 if cntry=="DK" & year==2004 /*CHES02*/
replace galtanL=4.13 if cntry=="DK" & year==2006 /*CHES06*/
replace galtanL=4.13 if cntry=="DK" & year==2008 /*CHES06*/
replace galtanL=5    if cntry=="DK" & year==2010 /*CHES10*/
replace galtanL=5    if cntry=="DK" & year==2012 /*CHES10*/
replace galtanL=5.2  if cntry=="DK" & year==2014 /*CHES14*/
replace galtanL=5.2  if cntry=="DK" & year==2016 /*CHES14*/
replace galtanL=5.2  if cntry=="DK" & year==2018 /*CHES14*/
replace galtanL=5    if cntry=="DK" & year==2020 /*CHES19*/

replace galtanL= 3.69 if cntry=="ES" & year==2002 /*CHES02*/
replace galtanL= 3.69 if cntry=="ES" & year==2004 /*CHES02*/
replace galtanL=2.15  if cntry=="ES" & year==2006 /*CHES06*/
replace galtanL=2.15  if cntry=="ES" & year==2008 /*CHES06*/
replace galtanL=2.33  if cntry=="ES" & year==2010 /*CHES10*/
replace galtanL=2.33  if cntry=="ES" & year==2012 /*CHES10*/
replace galtanL=2.2   if cntry=="ES" & year==2014 /*CHES14*/
replace galtanL=2.2   if cntry=="ES" & year==2016 /*CHES14*/
replace galtanL=2.2   if cntry=="ES" & year==2018 /*CHES14*/
replace galtanL=2.93  if cntry=="ES" & year==2020 /*CHES19*/

replace galtanL=3.17 if cntry=="FR" & year==2002 /*CHES02*/
replace galtanL=3.17 if cntry=="FR" & year==2004 /*CHES02*/
replace galtanL=2.75 if cntry=="FR" & year==2006 /*CHES06*/
replace galtanL=2.75 if cntry=="FR" & year==2008 /*CHES06*/
replace galtanL=2.33 if cntry=="FR" & year==2010 /*CHES10*/
replace galtanL=2.33 if cntry=="FR" & year==2012 /*CHES10*/
replace galtanL=3.36 if cntry=="FR" & year==2014 /*CHES14*/
replace galtanL=3.36 if cntry=="FR" & year==2016 /*CHES14*/
replace galtanL=3.36 if cntry=="FR" & year==2018 /*CHES14*/
replace galtanL=2.75 if cntry=="FR" & year==2020 /*CHES19*/

replace galtanL=4.83 if cntry=="GB" & year==2002 /*CHES02*/
replace galtanL=4.83 if cntry=="GB" & year==2004 /*CHES02*/
replace galtanL=4.67 if cntry=="GB" & year==2006 /*CHES06*/
replace galtanL=4.67 if cntry=="GB" & year==2008 /*CHES06*/
replace galtanL=4.06 if cntry=="GB" & year==2010 /*CHES10*/
replace galtanL=4.06 if cntry=="GB" & year==2012 /*CHES10*/
replace galtanL=3.43 if cntry=="GB" & year==2014 /*CHES14*/
replace galtanL=3.43 if cntry=="GB" & year==2016 /*CHES14*/
replace galtanL=3.43 if cntry=="GB" & year==2018 /*CHES14*/
replace galtanL=2.29 if cntry=="GB" & year==2020 /*CHES19*/

replace galtanL=3.86 if cntry=="GR" & year==2002 /*CHES02*/
replace galtanL=3.86 if cntry=="GR" & year==2004 /*CHES02*/
replace galtanL=3.25 if cntry=="GR" & year==2006 /*CHES06*/
replace galtanL=3.25 if cntry=="GR" & year==2008 /*CHES06*/
replace galtanL=2.82 if cntry=="GR" & year==2010 /*CHES10*/
replace galtanL=2.82 if cntry=="GR" & year==2012 /*CHES10*/
replace galtanL=4    if cntry=="GR" & year==2014 /*CHES14*/
replace galtanL=4    if cntry=="GR" & year==2016 /*CHES14*/
replace galtanL=4    if cntry=="GR" & year==2018 /*CHES14*/
replace galtanL=3.88 if cntry=="GR" & year==2020 /*CHES19*/

replace galtanL=3.75  if cntry=="IE" & year==2002 /*CHES02*/
replace galtanL=3.75  if cntry=="IE" & year==2004 /*CHES02*/
replace galtanL=2.89  if cntry=="IE" & year==2006 /*CHES06*/
replace galtanL=2.89  if cntry=="IE" & year==2008 /*CHES06*/
replace galtanL=3.75  if cntry=="IE" & year==2010 /*CHES10*/
replace galtanL=3.75  if cntry=="IE" & year==2012 /*CHES10*/
replace galtanL=3.75  if cntry=="IE" & year==2014 /*CHES14*/
replace galtanL=3.75  if cntry=="IE" & year==2016 /*CHES14*/
replace galtanL=3.75  if cntry=="IE" & year==2018 /*CHES14*/
replace galtanL=2.86  if cntry=="IE" & year==2020 /*CHES19*/

replace galtanL=2.54 if cntry=="IT" & year==2002 /*CHES02*/
replace galtanL=2.54 if cntry=="IT" & year==2004 /*CHES02*/
replace galtanL=2.88 if cntry=="IT" & year==2006 /*CHES06*/
replace galtanL=2.88 if cntry=="IT" & year==2008 /*CHES06*/
replace galtanL=.    if cntry=="IT" & year==2010 /*CHES10*/
replace galtanL=.    if cntry=="IT" & year==2012 /*CHES10*/
replace galtanL=.    if cntry=="IT" & year==2014 /*CHES14*/
replace galtanL=.    if cntry=="IT" & year==2016 /*CHES14*/
replace galtanL=.    if cntry=="IT" & year==2018 /*CHES14*/
replace galtanL=.    if cntry=="IT" & year==2020 /*CHES19*/

replace galtanL=1  if cntry=="LU" & year==2014 /*CHES14*/
replace galtanL=1  if cntry=="LU" & year==2016 /*CHES14*/
replace galtanL=1  if cntry=="LU" & year==2018 /*CHES14*/
replace galtanL=4  if cntry=="LU" & year==2020 /*CHES19*/

replace galtanL=2   if cntry=="NO" & year==2014 /*CHES14*/
replace galtanL=2   if cntry=="NO" & year==2016 /*CHES14*/
replace galtanL=2   if cntry=="NO" & year==2018 /*CHES14*/
replace galtanL=3.2 if cntry=="NO" & year==2020 /*CHES19*/

replace galtanL=2    if cntry=="CH" & year==2014 /*CHES14*/
replace galtanL=2    if cntry=="CH" & year==2016 /*CHES14*/
replace galtanL=2    if cntry=="CH" & year==2018 /*CHES14*/
replace galtanL=1.36 if cntry=="CH" & year==2020 /*CHES19*/

replace galtanL=3.25  if cntry=="NL" & year==2002 /*CHES02*/
replace galtanL=3.25  if cntry=="NL" & year==2004 /*CHES02*/
replace galtanL=3.7   if cntry=="NL" & year==2006 /*CHES06*/
replace galtanL=3.7   if cntry=="NL" & year==2008 /*CHES06*/
replace galtanL=4     if cntry=="NL" & year==2010 /*CHES10*/
replace galtanL=4     if cntry=="NL" & year==2012 /*CHES10*/
replace galtanL=3     if cntry=="NL" & year==2014 /*CHES14*/
replace galtanL=3     if cntry=="NL" & year==2016 /*CHES14*/
replace galtanL=3     if cntry=="NL" & year==2018 /*CHES14*/
replace galtanL=3.07  if cntry=="NL" & year==2020 /*CHES19*/

replace galtanL=4.83 if cntry=="SE" & year==2002 /*CHES02*/
replace galtanL=4.83 if cntry=="SE" & year==2004 /*CHES02*/
replace galtanL=4.22 if cntry=="SE" & year==2006 /*CHES06*/
replace galtanL=4.22 if cntry=="SE" & year==2008 /*CHES06*/
replace galtanL=4.21 if cntry=="SE" & year==2010 /*CHES10*/
replace galtanL=4.21 if cntry=="SE" & year==2012 /*CHES10*/
replace galtanL=3.62 if cntry=="SE" & year==2014 /*CHES14*/
replace galtanL=3.62 if cntry=="SE" & year==2016 /*CHES14*/
replace galtanL=3.62 if cntry=="SE" & year==2018 /*CHES14*/
replace galtanL=4.41 if cntry=="SE" & year==2020 /*CHES19*/

replace galtanL=3.43  if cntry=="PT" & year==2002 /*CHES02*/
replace galtanL=3.43  if cntry=="PT" & year==2004 /*CHES02*/
replace galtanL=3.8   if cntry=="PT" & year==2006 /*CHES06*/
replace galtanL=3.8   if cntry=="PT" & year==2008 /*CHES06*/
replace galtanL=2.33  if cntry=="PT" & year==2010 /*CHES10*/
replace galtanL=2.33  if cntry=="PT" & year==2012 /*CHES10*/
replace galtanL=3.16  if cntry=="PT" & year==2014 /*CHES14*/
replace galtanL=3.16  if cntry=="PT" & year==2016 /*CHES14*/
replace galtanL=3.16  if cntry=="PT" & year==2018 /*CHES14*/
replace galtanL=4.37  if cntry=="PT" & year==2020 /*CHES19*/

replace galtanL=3.89 if cntry=="FI" & year==2002 /*CHES02*/
replace galtanL=3.89 if cntry=="FI" & year==2004 /*CHES02*/
replace galtanL=5    if cntry=="FI" & year==2006 /*CHES06*/
replace galtanL=5    if cntry=="FI" & year==2008 /*CHES06*/
replace galtanL=4.7  if cntry=="FI" & year==2010 /*CHES10*/
replace galtanL=4.7  if cntry=="FI" & year==2012 /*CHES10*/
replace galtanL=3.22 if cntry=="FI" & year==2014 /*CHES14*/
replace galtanL=3.22 if cntry=="FI" & year==2016 /*CHES14*/
replace galtanL=3.22 if cntry=="FI" & year==2018 /*CHES14*/
replace galtanL=3.28 if cntry=="FI" & year==2020 /*CHES19*/

gen galtanR=.

replace galtanR=9    if cntry=="AT" & year==2002 /*CHES02*/
replace galtanR=9    if cntry=="AT" & year==2004 /*CHES02*/
replace galtanR=9.67 if cntry=="AT" & year==2006 /*CHES06*/
replace galtanR=9.67 if cntry=="AT" & year==2008 /*CHES06*/
replace galtanR=8.71 if cntry=="AT" & year==2010 /*CHES10*/
replace galtanR=8.71 if cntry=="AT" & year==2012 /*CHES10*/
replace galtanR=8.8  if cntry=="AT" & year==2014 /*CHES14*/
replace galtanR=8.8  if cntry=="AT" & year==2016 /*CHES14*/
replace galtanR=8.8  if cntry=="AT" & year==2018 /*CHES14*/
replace galtanR=8.9  if cntry=="AT" & year==2020 /*CHES19*/

replace galtanR=9.37 if cntry=="BE" & year==2002 /*CHES02*/
replace galtanR=9.37 if cntry=="BE" & year==2004 /*CHES02*/
replace galtanR=9.5  if cntry=="BE" & year==2006 /*CHES06*/
replace galtanR=9.5  if cntry=="BE" & year==2008 /*CHES06*/
replace galtanR=9.6  if cntry=="BE" & year==2010 /*CHES10*/
replace galtanR=9.6  if cntry=="BE" & year==2012 /*CHES10*/
replace galtanR=9    if cntry=="BE" & year==2014 /*CHES14*/
replace galtanR=9    if cntry=="BE" & year==2016 /*CHES14*/
replace galtanR=9    if cntry=="BE" & year==2018 /*CHES14*/
replace galtanR=8    if cntry=="BE" & year==2020 /*CHES19*/

replace galtanR=8.92 if cntry=="DK" & year==2002 /*CHES02*/
replace galtanR=8.92 if cntry=="DK" & year==2004 /*CHES02*/
replace galtanR=7.63 if cntry=="DK" & year==2006 /*CHES06*/
replace galtanR=7.63 if cntry=="DK" & year==2008 /*CHES06*/
replace galtanR=9.4  if cntry=="DK" & year==2010 /*CHES10*/
replace galtanR=9.4  if cntry=="DK" & year==2012 /*CHES10*/
replace galtanR=8.4  if cntry=="DK" & year==2014 /*CHES14*/
replace galtanR=8.4  if cntry=="DK" & year==2016 /*CHES14*/
replace galtanR=8.4  if cntry=="DK" & year==2018 /*CHES14*/
replace galtanR=8    if cntry=="DK" & year==2020 /*CHES19*/

replace galtanR=.    if cntry=="FI" & year==2002 /*CHES99*/
replace galtanR=.    if cntry=="FI" & year==2004 /*CHES99*/
replace galtanR=7.64 if cntry=="FI" & year==2006 /*CHES06*/
replace galtanR=7.64 if cntry=="FI" & year==2008 /*CHES06*/
replace galtanR=7.5  if cntry=="FI" & year==2010 /*CHES10*/
replace galtanR=7.5  if cntry=="FI" & year==2012 /*CHES10*/
replace galtanR=9.11 if cntry=="FI" & year==2014 /*CHES14*/
replace galtanR=9.11 if cntry=="FI" & year==2016 /*CHES14*/
replace galtanR=9.11 if cntry=="FI" & year==2018 /*CHES14*/
replace galtanR=8.78 if cntry=="FI" & year==2020 /*CHES19*/

replace galtanR=9.8  if cntry=="FR" & year==2002 /*CHES02*/
replace galtanR=9.8  if cntry=="FR" & year==2004 /*CHES02*/
replace galtanR=9.25 if cntry=="FR" & year==2006 /*CHES06*/
replace galtanR=9.25 if cntry=="FR" & year==2008 /*CHES10*/
replace galtanR=9.55 if cntry=="FR" & year==2010 /*CHES10*/
replace galtanR=9.55 if cntry=="FR" & year==2012 /*CHES10*/
replace galtanR=8.92 if cntry=="FR" & year==2014 /*CHES14*/
replace galtanR=8.92 if cntry=="FR" & year==2016 /*CHES14*/
replace galtanR=8.92 if cntry=="FR" & year==2018 /*CHES14*/
replace galtanR=8.12 if cntry=="FR" & year==2020 /*RN, CHES19*/

replace galtanR=.    if cntry=="GR" & year==2002 /*CHES02*/
replace galtanR=.    if cntry=="GR" & year==2004 /*CHES02*/
replace galtanR=9.63 if cntry=="GR" & year==2006 /*CHES06*/
replace galtanR=9.63 if cntry=="GR" & year==2008 /*CHES10*/
replace galtanR=9.55 if cntry=="GR" & year==2010 /*CHES10*/
replace galtanR=9.55 if cntry=="GR" & year==2012 /*CHES10*/
replace galtanR=8.33 if cntry=="GR" & year==2014 /*CHES14*/
replace galtanR=8.33 if cntry=="GR" & year==2016 /*CHES14*/
replace galtanR=8.33 if cntry=="GR" & year==2018 /*CHES14*/
replace galtanR=9.37 if cntry=="GR" & year==2020 /*CHES19*/

replace galtanR=8.23 if cntry=="IT" & year==2002 /*CHES02*/
replace galtanR=8.23 if cntry=="IT" & year==2004 /*CHES02*/
replace galtanR=8.75 if cntry=="IT" & year==2006 /*CHES06*/
replace galtanR=8.75 if cntry=="IT" & year==2008 /*CHES*/
replace galtanR=8.44 if cntry=="IT" & year==2010 /*CHES10*/
replace galtanR=8.44 if cntry=="IT" & year==2012 /*CHES10*/
replace galtanR=9.14 if cntry=="IT" & year==2014 /*CHES14*/
replace galtanR=9.14 if cntry=="IT" & year==2016 /*CHES14*/
replace galtanR=9.14 if cntry=="IT" & year==2018 /*CHES14*/
replace galtanR=9.21 if cntry=="IT" & year==2020 /*CHES19*/

replace galtanR=5.44 if cntry=="NL" & year==2002 /*CHES02, LPF*/
replace galtanR=5.44 if cntry=="NL" & year==2004 /*CHES02, LPF*/
replace galtanR=6.57 if cntry=="NL" & year==2006 /*CHES06, PVV*/
replace galtanR=6.57 if cntry=="NL" & year==2008 /*CHES10, PVV*/
replace galtanR=7.15 if cntry=="NL" & year==2010 /*CHES10, PVV*/
replace galtanR=7.78 if cntry=="NL" & year==2014 /*CHES14, PVV*/
replace galtanR=7.78 if cntry=="NL" & year==2016 /*CHES14, PVV*/
replace galtanR=7.78 if cntry=="NL" & year==2018 /*CHES14, PVV*/
replace galtanR=7.23 if cntry=="NL" & year==2020 /*CHES19, PVV*/

replace galtanR=.    if cntry=="SE" & year==2002 /*CHES02*/
replace galtanR=.    if cntry=="SE" & year==2004 /*CHES02*/
replace galtanR=.    if cntry=="SE" & year==2006 /*CHES06*/
replace galtanR=.    if cntry=="SE" & year==2008 /*CHES10*/
replace galtanR=8.25 if cntry=="SE" & year==2010 /*CHES10*/
replace galtanR=8.25 if cntry=="SE" & year==2012 /*CHES10*/
replace galtanR=9.24  if cntry=="SE" & year==2014 /*CHES14*/
replace galtanR=9.24  if cntry=="SE" & year==2016 /*CHES14*/
replace galtanR=9.24  if cntry=="SE" & year==2018 /*CHES14*/
replace galtanR=8.76  if cntry=="SE" & year==2020 /*CHES19*/

replace galtanR=7.5 if cntry=="NO" & year==2014 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=7.5 if cntry=="NO" & year==2016 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=7.5 if cntry=="NO" & year==2018 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=6.8 if cntry=="NO" & year==2020 /*CHES14, taken seperatly from the 2019 wave */

replace galtanR=9.37 if cntry=="CH" & year==2014 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=9.37 if cntry=="CH" & year==2016 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=9.37 if cntry=="CH" & year==2018 /*CHES14, taken seperatly from the 2014 wave */
replace galtanR=9.36 if cntry=="CH" & year==2020 /*CHES19, taken seperatly from the 2014 wave */

replace galtanR=9.29 if cntry=="GB"& year==2016 /*CHES14*/

***********************
gen nonwstrnimg=0
replace nonwstrnimg=1 if imgstatus==4
replace nonwstrnimg=1 if imgstatus==5

bys nonwstrnimg: ta prtyfam_sd if vote==1
bys muslim: ta prtyfam_sd if vote==1
bys muslimcat: ta prtyfam_sd if vote==1
bys bigmnrty: ta prtyfam_sd if vote==1
*** Spoken language ***
gen germanic= lnghom1=="AFR"|lnghom1=="DAN"|lnghom1=="DUT"|lnghom1=="ENG"/*
*/|lnghom1=="ANG"|lnghom1=="FRY"|lnghom1=="GER"|lnghom1=="GEM"|lnghom1=="ICE"/*
*/|lnghom1=="NDS"|lnghom1=="NOR"|lnghom1=="NOB"|lnghom1=="NNO"|lnghom1=="SCO"|lnghom1=="SWE"|lnghom1=="GSW"|lnghom1=="YID"  | ///
lnghoma=="AFR"|lnghoma=="DAN"|lnghoma=="DUT"|lnghoma=="ENG"/*
*/|lnghoma=="ANG"|lnghoma=="FRY"|lnghoma=="GER"|lnghoma=="GEM"|lnghoma=="ICE"/*
*/|lnghoma=="NDS"|lnghoma=="NOR"|lnghoma=="NOB"|lnghoma=="NNO"|lnghoma=="SCO"|lnghoma=="SWE"|lnghoma=="GSW"|lnghoma=="YID"

gen latin= lnghom1=="RUP"|lnghom1=="AST"|lnghom1=="CAT"|lnghom1=="COS"|lnghom1=="FRE"|lnghom1=="FRM"/*
*/|lnghom1=="GLG"|lnghom1=="ITA"|lnghom1=="LAT"|lnghom1=="POR"|lnghom1=="ROH"|lnghom1=="ROA"|lnghom1=="RUM"|lnghom1=="SRD"/*
*/|lnghom1=="SCN"|lnghom1=="SPA"|lnghom1=="WLN" | lnghoma=="RUP"|lnghoma=="AST"|lnghoma=="CAT"|lnghoma=="COS"|lnghoma=="FRE"|lnghoma=="FRM"/*
*/|lnghoma=="GLG"|lnghoma=="ITA"|lnghoma=="LAT"|lnghoma=="POR"|lnghoma=="ROH"|lnghoma=="ROA"|lnghoma=="RUM"|lnghoma=="SRD"/*
*/|lnghoma=="SCN"|lnghoma=="SPA"|lnghoma=="WLN"

gen slavic= lnghom1=="BEL"|lnghom1=="BOS"|lnghom1=="BUL"|lnghom1=="HRV"|lnghom1=="CZE"|lnghom1=="CSB"|lnghom1=="POL"|lnghom1=="RUS"/*
*/|lnghom1=="SLA"|lnghom1=="SLO"|lnghom1=="SLV"|lnghom1=="UKR"|lnghom1=="SCR" | lnghoma=="BEL"|lnghoma=="BOS"|lnghoma=="BUL"|lnghoma=="HRV"|lnghom1=="CZE"|lnghom1=="CSB"|lnghom1=="POL"|lnghom1=="RUS"/*
*/|lnghoma=="SLA"|lnghoma=="SLO"|lnghoma=="SLV"|lnghoma=="UKR"|lnghoma=="SCR"

gen finnougric= lnghom1=="EST"|lnghom1=="FIN"|lnghom1=="FIU"|lnghom1=="HUN"|lnghom1=="VOT" | lnghoma=="EST"|lnghoma=="FIN"|lnghoma=="FIU"|lnghoma=="HUN"|lnghoma=="VOT"

gen baltic= lnghom1=="LAV"|lnghom1=="LIT" | lnghoma=="LAV"|lnghoma=="LIT"

gen greek=lnghom1=="GRE" | lnghoma=="GRE"

gen turkic=lnghom1=="CHV"|lnghom1=="TUR"|lnghom1=="UIG"|lnghom1=="SAH"|lnghom1=="KUM"|lnghom1=="BAK"|lnghom1=="TAT" | lnghoma=="CHV"|lnghoma=="TUR"|lnghoma=="UIG"|lnghoma=="SAH"|lnghoma=="KUM"|lnghoma=="BAK"|lnghoma=="TAT"

gen balto_slavic=baltic+slavic

gen semitic=lnghom1=="ARA"|lnghom1=="HEB" |lnghoma=="ARA"|lnghoma=="HEB"

gen greek_turc=greek+turkic
gen other   =1-germanic-latin-slavic-finnougric-baltic-greek
gen nongerman =1-germanic	
gen nonlatin=1-latin

/*TABL1*/

bys muslim:ta  prtyfam_sd if vote==1

estpost summarize agea Male manual unemp3 religiousity  polintr trstplt  lrscale popdens eduyrs if prtyfam_sd==1  & vote==1  & muslim==1
estpost summarize agea Male manual unemp3 religiousity  polintr trstplt  lrscale popdens eduyrs if prtyfam_sd==1  & vote==1  & muslim==0

/*ADD INCMOE INTO REGRESSIONS*/
bys year:ta  hinctnt /*2002, 2004, 2006*/
bys year:ta hinctnta /*2008-2018*/

/*FIGURE2*/
/*INCOME TEST: INCOME DIST. OF immigrants and natives*/
set scheme plotplain
ksmirnov hinctnt, by(muslim)
ksmirnov hinctnta, by(muslim)
tab hinctnt muslim , chi col exact

twoway histogram hinctnta if muslim==0 & hinctnta<13, width(.9) color(navy%25) || ///
       histogram hinctnta if muslim==1  & hinctnta<13,  width(.9) color(maroon%25) ///
       legend(off)  title("Household income dist. for Muslims and natives 2002-2020")
graph save "income dist.", replace	   

/*CLASS DISTRIBUTION*/

twoway histogram man_ord if muslim==0 , width(.95) color(navy%25) || ///
       histogram man_ord if muslim==1 ,  width(.95) color(maroon%25)  ///
       legend(off) title("Class dist. for Muslims and nin-Muslims 2002-2018") xlabel(1 "Legislators, and managers" ///
2 "Clerks"  3 "Technicians" 4 "Professionals" ///
5 "Service workers" 6 "Elementary occupations"  ///
7 "Craft and trades workers" 8 "Machine operators" ) 
graph save "class dist."

graph combine  "C:\Users\User\Downloads\income dist..gph"  "C:\Users\User\Downloads\class dist..gph"

/*TABLE 3: REGRESSION RESULTS*/	   

probit prtyfam_sd  i.muslim i.country i.year if vote==1
estimates store a1
margin i.muslim, atmeans 

*probit prtyfam_sd i.bigmnrty i.country i.year if vote==1
*estimates store a2

probit prtyfam_sd  i.bigmnrty##c.man unemp3 Male eduyrs popdens agea sqrage  lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store b2
*FIGURE3A*/
margin i.bigmnrty, atmeans at(man= (.2 (.2).8) )
marginsplot
graph save "manual muslims predicted prob.gph", replace
/*
probit prtyfam_sd  i.muslim##i.unemp3 man Male eduyrs popdens agea sqrage  lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store c1
*/
probit prtyfam_sd  i.bigmnrty##i.unemp3 man Male eduyrs popdens agea sqrage  lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store c2
/*FIGURE3B*/
margin i.bigmnrty, atmeans at(unemp3= (0 1 ))
marginsplot
graph save "unemployed muslims predicted prob.gph", replace
/*integration income	
probit prtyfam_sd  i.bigmnrty##c.hinctnta unemp3 Male  man eduyrs popdens agea sqrage   lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store c3
margin i.bigmnrty, atmeans at(hinctnta= (1 (1)10 ))
marginsplot
*/
/*language integration*/

probit prtyfam_sd  i.bigmnrty##i.other Male man eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store d2
/*FIGURE3C*/
margin i.bigmnrty, atmeans at(other= (0 1) )
marginsplot
graph save "language muslims predicted prob.gph", replace
/*PERCIEVED DISCRMINATION*/
probit prtyfam_sd  i.bigmnrty##i.dscrrlg Male man eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store f2
/*FIGURE D1*/
margin i.bigmnrty, atmeans at(dscrrlg= (0 1) )
marginsplot
graph save "discrimination muslims.gph", replace
/*RR VOE SHARE*/
probit prtyfam_sd  i.muslim##c.votshare Male man ///  
eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store g1

probit prtyfam_sd  i.muslim##c.seatshare Male man ///  
eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
estimates store h1

logit prtyfam_sd  i.bigmnrty##c.seatshare Male man ///  
eduyrs popdens agea sqrage  unemp3  religiousity polintr trstplt ///
i.country i.year if vote==1
estimates store h2
/*FIGURE D2*/
margin i.bigmnrty, atmeans at(seatshare= (0 (.05).4))
marginsplot
graph save "rr seat share.gph", replace

/*APPENDIX D2*/
probit prtyfam_sd  i.muslim##c.epvoteshare Male man ///  
eduyrs popdens agea sqrage  unemp3  lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
margin i.muslim, atmeans at(epvoteshare= (0 (.05).4 ))
marginsplot
estimates store i1



/*FIGURE 3 (COMBINED)*/		
grc1leg "C:\Users\User\Downloads\manual muslims predicted prob.gph" "C:\Users\User\Downloads\unemployed muslims predicted prob.gph" "C:\Users\User\Downloads\language muslims predicted prob.gph", row(1) ycommon
/*FIGURE 4 (COMBINED)*/
grc1leg "C:\Users\User\Downloads\discrimination muslims.gph" "C:\Users\User\Downloads\rr seat share.gph", row(1) ycommon

/*natives who feel discriminated against vote for the rr, Muslims' vote for the left
mlogit prtyfam_vote i.bigmnrty##i.dscrrlg Male man ///  
 eduyrs popdens agea sqrage  unemp3 religiousity  lrscale polintr trstplt  ///
 i.country i.year if vote==1, base(3) iter(20)
outreg2 using muslim.doc, replace dec(2) drop(i.essround i.country) addtext(ESS round and country FE, YES)

*/

esttab a1 b2 c1 d2 f1 g1 h1 i1  ///
using muslims.rtf, nogap se(2) b(2) label replace ar2 star(+ 0.10 * 0.05 ** .01 *** .001)  ///
title("Support for SDPs (Probit Models, ESS 1-10)")
  
esttab  i1  ///
using muslims.rtf, nogap se(2) b(2) label replace ar2 star(+ 0.10 * 0.05 ** .01 *** .001)  ///
title("Support for SDPs (Probit Models, ESS 1-10)")  



/*COUNTERFACTUALS - WILL THE MUSLIM-NATIVE GAP DECLINE IF MUSLIMS HAVE NATIVES' CARACTERISTICS?*/
probit prtyfam_sd  i.muslim  Male manual eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
i.country i.year if vote==1
margins,  at ((mean) _all muslim=(0 1)) /*true charactersitics*/

/*Muslims and natives charactersitics*/
by muslim, sort: sum agea sqrage Male unemp3 religiousity  polintr trstplt  lrscale popdens eduyrs manual if vote==1

margins,  at ((mean) _all muslim==1 agea==51.94 sqrage== 2987 Male==.49 unemp3==.25 religiousity==4.58  polintr==2.34 trstplt==4.08 lrscale==5.07 popdens==3.01 eduyrs==13.08 manual==44.52 ) /*Muslims' predicted prob. to vote left given natives' charactersitics*/

margins,  at ((mean) _all muslim==0 agea==51.94 sqrage== 2987 Male==.49 unemp3==.25 religiousity==4.58  polintr==2.34 trstplt==4.08 lrscale==5.07 popdens==3.01 eduyrs==13.08 manual==44.52 )  /*Natives' predicted prob. to vote left given natives' charactersitics*/

margins,  at ((mean) _all muslim==0 agea==39.68 sqrage== 1751 Male==.54 unemp3==.45 religiousity==7.1  polintr==2.45 trstplt==4.44  lrscale==4.2 popdens==3.79 eduyrs==12.85 manual==49.58 ) /*Natives' predicted prob. to vote left given Muslims' charactersitics*/

margins,  at ((mean) _all muslim==1 agea==39.68 sqrage== 1751 Male==.54 unemp3==.45 religiousity==7.1  polintr==2.45 trstplt==4.44  lrscale==4.2 popdens==3.79 eduyrs==12.85 manual==49.58 )  /*Muslims' predicted prob. to vote left given Muslims' charactersitics*/


 
************************************************	
*BRITISH CASE*
gen rrvs=.
replace rrvs=0.8 if cntry=="GB" & regiongb==1 & year==2002 
replace rrvs=0.8 if cntry=="GB" & regiongb==2 & year==2002 
replace rrvs=1.9 if cntry=="GB" & regiongb==3 & year==2002 
replace rrvs=1   if cntry=="GB" & regiongb==4 & year==2002 
replace rrvs=2.3 if cntry=="GB" & regiongb==5 & year==2002 
replace rrvs=2.3 if cntry=="GB" & regiongb==6 & year==2002 
replace rrvs=.8  if cntry=="GB" & regiongb==7 & year==2002 
replace rrvs=.9  if cntry=="GB" & regiongb==8 & year==2002 
replace rrvs=3.4 if cntry=="GB" & regiongb==9 & year==2002 
replace rrvs=.9  if cntry=="GB" & regiongb==10 & year==2002 
replace rrvs=.2  if cntry=="GB" & regiongb==11 & year==2002 
replace rrvs=0   if cntry=="GB" & regiongb==12 & year==2002 
replace rrvs=0.8 if cntry=="GB" & regiongb==1 & year==2004 
replace rrvs=0.8 if cntry=="GB" & regiongb==2 & year==2004 
replace rrvs=1.9 if cntry=="GB" & regiongb==3 & year==2004 
replace rrvs=1   if cntry=="GB" & regiongb==4 & year==2004 
replace rrvs=2.3 if cntry=="GB" & regiongb==5 & year==2004 
replace rrvs=2.3 if cntry=="GB" & regiongb==6 & year==2004 
replace rrvs=.8  if cntry=="GB" & regiongb==7 & year==2004 
replace rrvs=.9  if cntry=="GB" & regiongb==8 & year==2004 
replace rrvs=3.4 if cntry=="GB" & regiongb==9 & year==2004 
replace rrvs=.9  if cntry=="GB" & regiongb==10 & year==2004 
replace rrvs=.2  if cntry=="GB" & regiongb==11 & year==2004 
replace rrvs=0   if cntry=="GB" & regiongb==12 & year==2004 
replace rrvs=1.1 if cntry=="GB" & regiongb==1 & year==2006 
replace rrvs=2.1 if cntry=="GB" & regiongb==2 & year==2006 
replace rrvs=1.5 if cntry=="GB" & regiongb==3 & year==2006 
replace rrvs=2.5 if cntry=="GB" & regiongb==4 & year==2006 
replace rrvs=4.2 if cntry=="GB" & regiongb==5 & year==2006 
replace rrvs=3.4 if cntry=="GB" & regiongb==6 & year==2006 
replace rrvs=2.9 if cntry=="GB" & regiongb==7 & year==2006 
replace rrvs=1.5 if cntry=="GB" & regiongb==8 & year==2006 
replace rrvs=3.2 if cntry=="GB" & regiongb==9 & year==2006 
replace rrvs=1.5 if cntry=="GB" & regiongb==10 & year==2006 
replace rrvs=.4  if cntry=="GB" & regiongb==11 & year==2006 
replace rrvs=0   if cntry=="GB" & regiongb==12 & year==2006 
replace rrvs=1.1 if cntry=="GB" & regiongb==1 & year==2008 
replace rrvs=2.1 if cntry=="GB" & regiongb==2 & year==2008 
replace rrvs=1.5 if cntry=="GB" & regiongb==3 & year==2008 
replace rrvs=2.5 if cntry=="GB" & regiongb==4 & year==2008 
replace rrvs=4.2 if cntry=="GB" & regiongb==5 & year==2008 
replace rrvs=3.4 if cntry=="GB" & regiongb==6 & year==2008 
replace rrvs=2.9 if cntry=="GB" & regiongb==7 & year==2008 
replace rrvs=1.5 if cntry=="GB" & regiongb==8 & year==2008 
replace rrvs=3.2 if cntry=="GB" & regiongb==9 & year==2008 
replace rrvs=1.5 if cntry=="GB" & regiongb==10 & year==2008 
replace rrvs=.4  if cntry=="GB" & regiongb==11 & year==2008 
replace rrvs=0   if cntry=="GB" & regiongb==12 & year==2008 
replace rrvs=2.7 if cntry=="GB" & region =="UKC" & year==2010 
replace rrvs=3.2 if cntry=="GB" & region =="UKD" & year==2010 
replace rrvs=3   if cntry=="GB" & region =="UKE" & year==2010
replace rrvs=3.3 if cntry=="GB" & region =="UKF" & year==2010 
replace rrvs=5.2 if cntry=="GB" & region =="UKG" & year==2010 
replace rrvs=4.5 if cntry=="GB" & region =="UKK" & year==2010 
replace rrvs=4.3 if cntry=="GB" & region =="UKH" & year==2010 
replace rrvs=1.7 if cntry=="GB" & region =="UKI" & year==2010
replace rrvs=4.1 if cntry=="GB" & region =="UKJ" & year==2010 
replace rrvs=2.4 if cntry=="GB" & region =="UKL" & year==2010
replace rrvs=.7  if cntry=="GB" & region =="UKM" & year==2010
replace rrvs=0   if cntry=="GB" & region =="UKN" & year==2010 
replace rrvs=2.7 if cntry=="GB" & region =="UKC" & year==2012 
replace rrvs=3.2 if cntry=="GB" & region =="UKD" & year==2012 
replace rrvs=3   if cntry=="GB" & region =="UKE" & year==2012
replace rrvs=3.3 if cntry=="GB" & region =="UKF" & year==2012 
replace rrvs=5.2 if cntry=="GB" & region =="UKG" & year==2012 
replace rrvs=4.5 if cntry=="GB" & region =="UKK" & year==2012 
replace rrvs=4.3 if cntry=="GB" & region =="UKH" & year==2012 
replace rrvs=1.7 if cntry=="GB" & region =="UKI" & year==2012
replace rrvs=4.1 if cntry=="GB" & region =="UKJ" & year==2012 
replace rrvs=2.4 if cntry=="GB" & region =="UKL" & year==2012
replace rrvs=.7  if cntry=="GB" & region =="UKM" & year==2012
replace rrvs=0   if cntry=="GB" & region =="UKN" & year==2012
replace rrvs=2.7 if cntry=="GB" & region =="UKC" & year==2014 
replace rrvs=3.2 if cntry=="GB" & region =="UKD" & year==2014 
replace rrvs=3   if cntry=="GB" & region =="UKE" & year==2014
replace rrvs=3.3 if cntry=="GB" & region =="UKF" & year==2014 
replace rrvs=5.2 if cntry=="GB" & region =="UKG" & year==2014 
replace rrvs=4.5 if cntry=="GB" & region =="UKK" & year==2014 
replace rrvs=4.3 if cntry=="GB" & region =="UKH" & year==2014 
replace rrvs=1.7 if cntry=="GB" & region =="UKI" & year==2014
replace rrvs=4.1 if cntry=="GB" & region =="UKJ" & year==2014 
replace rrvs=2.4 if cntry=="GB" & region =="UKL" & year==2014
replace rrvs=.7  if cntry=="GB" & region =="UKM" & year==2014
replace rrvs=0   if cntry=="GB" & region =="UKN" & year==2014
replace rrvs=17 if cntry=="GB" & region =="UKC" & year==2016 
replace rrvs=13.8 if cntry=="GB" & region =="UKD" & year==2016
replace rrvs=16.5 if cntry=="GB" & region =="UKE" & year==2016
replace rrvs=15.9 if cntry=="GB" & region =="UKF" & year==2016 
replace rrvs=20.3 if cntry=="GB" & region =="UKG" & year==2016 
replace rrvs=13.7 if cntry=="GB" & region =="UKK" & year==2016 
replace rrvs=16.2 if cntry=="GB" & region =="UKH" & year==2016
replace rrvs=8.2 if cntry=="GB" & region =="UKI" & year==2016
replace rrvs=15 if cntry=="GB" & region =="UKJ" & year==2016
replace rrvs=13.8 if cntry=="GB" & region =="UKL" & year==2016
replace rrvs=1.6 if cntry=="GB" & region =="UKM" & year==2016
replace rrvs=2 if cntry=="GB" & region =="UKN" & year==2016
replace rrvs=3.9 if cntry=="GB" & region =="UKC" & year==2018 
replace rrvs=2 if cntry=="GB" & region =="UKD" & year==2018
replace rrvs=2.8 if cntry=="GB" & region =="UKE" & year==2018
replace rrvs=2.4 if cntry=="GB" & region =="UKF" & year==2018 
replace rrvs=2.4 if cntry=="GB" & region =="UKG" & year==2018 
replace rrvs=1.1 if cntry=="GB" & region =="UKK" & year==2018 
replace rrvs=2.6 if cntry=="GB" & region =="UKH" & year==2018
replace rrvs=1.3 if cntry=="GB" & region =="UKI" & year==2018
replace rrvs=2.3 if cntry=="GB" & region =="UKJ" & year==2018
replace rrvs=2 if cntry=="GB" & region =="UKL" & year==2018
replace rrvs=.2 if cntry=="GB" & region =="UKM" & year==2018
replace rrvs=0 if cntry=="GB" & region =="UKN" & year==2018
 
gen crimeuk=.
gen crimeuks=.

replace crimeuk=1450 if cntry=="GB" & regiongb==1 & year==2002  /*north east*/
replace crimeuks=0.000540432 if cntry=="GB" & regiongb==1 & year==2002  /*north east*/

replace crimeuk=4392 if cntry=="GB" & regiongb==2 & year==2002 /*north west*/
replace crimeuks=0.000584345 if cntry=="GB" & regiongb==2 & year==2002 /*north west*/

replace crimeuk=1331 if cntry=="GB" & regiongb==3 & year==2002 /*Yorkshire*/
replace crimeuks=0.000240198 if cntry=="GB" & regiongb==3 & year==2002 /*Yorkshire*/

replace crimeuk=2443   if cntry=="GB" & regiongb==4 & year==2002
replace crimeuks=0.000495042 if cntry=="GB" & regiongb==4 & year==2002 
 
replace crimeuk=3574 if cntry=="GB" & regiongb==5 & year==2002 
replace crimeuks=0.000593525 if cntry=="GB" & regiongb==5 & year==2002 

replace crimeuk=2015 if cntry=="GB" & regiongb==6 & year==2002
replace crimeuks=0.00034953 if cntry=="GB" & regiongb==6 & year==2002 
 
replace crimeuk=1929  if cntry=="GB" & regiongb==7 & year==2002
replace crimeuks=0.000301477 if cntry=="GB" & regiongb==7 & year==2002 
 
replace crimeuk=9924  if cntry=="GB" & regiongb==8 & year==2002
replace crimeuks=0.001120681 if cntry=="GB" & regiongb==8 & year==2002 
 
replace crimeuk=2662 if cntry=="GB" & regiongb==9 & year==2002 
replace crimeuks=0.0002838 if cntry=="GB" & regiongb==9 & year==2002 

replace crimeuk=1314  if cntry=="GB" & regiongb==10 & year==2002 
replace crimeuks=0.000419588 if cntry=="GB" & regiongb==10 & year==2002 

replace crimeuk=.  if cntry=="GB" & regiongb==11 & year==2002 
replace crimeuk=.   if cntry=="GB" & regiongb==12 & year==2002
replace crimeuks=.  if cntry=="GB" & regiongb==11 & year==2002 
replace crimeuks=.   if cntry=="GB" & regiongb==12 & year==2002 
 
replace crimeuk=1363 if cntry=="GB" & regiongb==1 & year==2004 
replace crimeuks=0.000508006 if cntry=="GB" & regiongb==1 & year==2004 

replace crimeuk=5408 if cntry=="GB" & regiongb==2 & year==2004
replace crimeuks=0.000719521 if cntry=="GB" & regiongb==2 & year==2004 
 
replace crimeuk=2625 if cntry=="GB" & regiongb==3 & year==2004
replace crimeuks=0.000473719 if cntry=="GB" & regiongb==3 & year==2004 
 
replace crimeuk=2620   if cntry=="GB" & regiongb==4 & year==2004 
replace crimeuks=0.000530908 if cntry=="GB" & regiongb==4 & year==2004 

replace crimeuk=23940 if cntry=="GB" & regiongb==5 & year==2004 
replace crimeuks=0.000654305 if cntry=="GB" & regiongb==5 & year==2004 

replace crimeuk=2421 if cntry=="GB" & regiongb==6 & year==2004 
replace crimeuks=0.000419957 if cntry=="GB" & regiongb==6 & year==2004 

replace crimeuk=2624  if cntry=="GB" & regiongb==7 & year==2004 
replace crimeuks=0.000413535  if cntry=="GB" & regiongb==7 & year==2004
 

replace crimeuk=9528  if cntry=="GB" & regiongb==8 & year==2004
replace crimeuks=0.001075962 if cntry=="GB" & regiongb==8 & year==2004 
 
replace crimeuk=3033 if cntry=="GB" & regiongb==9 & year==2004
replace crimeuks=0.000323353 if cntry=="GB" & regiongb==9 & year==2004 
 
replace crimeuk=1438  if cntry=="GB" & regiongb==10 & year==2004 
replace crimeuks=0.000459184 if cntry=="GB" & regiongb==10 & year==2004 

replace crimeuk=.  if cntry=="GB" & regiongb==11 & year==2004 
replace crimeuk=.   if cntry=="GB" & regiongb==12 & year==2004
replace crimeuks=.  if cntry=="GB" & regiongb==11 & year==2004 
replace crimeuks=.   if cntry=="GB" & regiongb==12 & year==2004 
 
replace crimeuk=1620 if cntry=="GB" & regiongb==1 & year==2006
replace crimeuks=0.000603793 if cntry=="GB" & regiongb==1 & year==2006 
 
replace crimeuk=6982 if cntry=="GB" & regiongb==2 & year==2006
replace crimeuks=0.000928938 if cntry=="GB" & regiongb==2 & year==2006 
 
replace crimeuk=4552 if cntry=="GB" & regiongb==3 & year==2006 
replace crimeuks=0.000821474 if cntry=="GB" & regiongb==3 & year==2006 

replace crimeuk=2722 if cntry=="GB" & regiongb==4 & year==2006
replace crimeuks=0.000551577 if cntry=="GB" & regiongb==4 & year==2006 
 
replace crimeuk=4696 if cntry=="GB" & regiongb==5 & year==2006
replace crimeuks=0.000779852 if cntry=="GB" & regiongb==5 & year==2006 
 
replace crimeuk=2901 if cntry=="GB" & regiongb==6 & year==2006
replace crimeuks=0.000503219 if cntry=="GB" & regiongb==6 & year==2006 
 
replace crimeuk=3025 if cntry=="GB" & regiongb==7 & year==2006 
replace crimeuks=0.000472767 if cntry=="GB" & regiongb==7 & year==2006 

replace crimeuk=8844 if cntry=="GB" & regiongb==8 & year==2006
replace crimeuks=0.00099872 if cntry=="GB" & regiongb==8 & year==2006 
 
replace crimeuk=4601 if cntry=="GB" & regiongb==9 & year==2006 
replace crimeuks=0.00049052 if cntry=="GB" & regiongb==9 & year==2006 

replace crimeuk=1516 if cntry=="GB" & regiongb==10 & year==2006 
replace crimeuks=0.000484091 if cntry=="GB" & regiongb==10 & year==2006 

replace crimeuk=.  if cntry=="GB" & regiongb==11 & year==2006 
replace crimeuk=.   if cntry=="GB" & regiongb==12 & year==2006
replace crimeuks=.  if cntry=="GB" & regiongb==11 & year==2006 
replace crimeuks=.   if cntry=="GB" & regiongb==12 & year==2006 
 
replace crimeuk=1364 if cntry=="GB" & regiongb==1 & year==2008 
replace crimeuks=0.000508379 if cntry=="GB" & regiongb==1 & year==2008 

replace crimeuk=6502 if cntry=="GB" & regiongb==2 & year==2008
replace crimeuks=0.000865075 if cntry=="GB" & regiongb==2 & year==2008 
 
replace crimeuk=3999 if cntry=="GB" & regiongb==3 & year==2008 
replace crimeuks=0.000721677 if cntry=="GB" & regiongb==3 & year==2008 

replace crimeuk=2844 if cntry=="GB" & regiongb==4 & year==2008
replace crimeuks=0.000576299 if cntry=="GB" & regiongb==4 & year==2008 

replace crimeuk=4928 if cntry=="GB" & regiongb==5 & year==2008 
replace crimeuks=0.00081838 if cntry=="GB" & regiongb==5 & year==2008 

replace crimeuk=2477 if cntry=="GB" & regiongb==6 & year==2008 
replace crimeuks=0.000429671 if cntry=="GB" & regiongb==6 & year==2008 

replace crimeuk=3099 if cntry=="GB" & regiongb==7 & year==2008 
replace crimeuks=0.000470267 if cntry=="GB" & regiongb==7 & year==2008 

replace crimeuk=7430 if cntry=="GB" & regiongb==8 & year==2008
replace crimeuks=0.000839042 if cntry=="GB" & regiongb==8 & year==2008 

replace crimeuk=4512 if cntry=="GB" & regiongb==9 & year==2008 
replace crimeuks=0.000481032 if cntry=="GB" & regiongb==9 & year==2008 

replace crimeuk=1286 if cntry=="GB" & regiongb==10 & year==2008
replace crimeuk=0.000410647 if cntry=="GB" & regiongb==10 & year==2008 

replace crimeuk=.  if cntry=="GB" & regiongb==11 & year==2008 
replace crimeuk=.   if cntry=="GB" & regiongb==12 & year==2008 
replace crimeuks=.  if cntry=="GB" & regiongb==11 & year==2008 
replace crimeuks=.   if cntry=="GB" & regiongb==12 & year==2008 

replace crimeuk=1155 if cntry=="GB" & region =="UKC" & year==2010
replace crimeuks=0.000430482 if cntry=="GB" & region =="UKC" & year==2010 

replace crimeuk=5706 if cntry=="GB" & region =="UKD" & year==2010 
replace crimeuks=0.000759169 if cntry=="GB" & region =="UKD" & year==2010 

replace crimeuk=3156   if cntry=="GB" & region =="UKE" & year==2010
replace crimeuks=0.000569545 if cntry=="GB" & region =="UKE" & year==2010

replace crimeuk=2773 if cntry=="GB" & region =="UKF" & year==2010 
replace crimeuks=0.000561912 if cntry=="GB" & region =="UKF" & year==2010 

replace crimeuk=4225 if cntry=="GB" & region =="UKG" & year==2010 
replace crimeuks=0.000701635 if cntry=="GB" & region =="UKG" & year==2010 

replace crimeuk=2601 if cntry=="GB" & region =="UKK" & year==2010 
replace crimeuks=0.00045118 if cntry=="GB" & region =="UKK" & year==2010 

replace crimeuk=2897 if cntry=="GB" & region =="UKH" & year==2010 
replace crimeuks=0.000452763 if cntry=="GB" & region =="UKH" & year==2010 

replace crimeuk=8058 if cntry=="GB" & region =="UKI" & year==2010
replace crimeuks=0.00090996 if cntry=="GB" & region =="UKI" & year==2010

replace crimeuk=3845 if cntry=="GB" & region =="UKJ" & year==2010
replace crimeuks=0.000409922 if cntry=="GB" & region =="UKJ" & year==2010 

replace crimeuk=1288 if cntry=="GB" & region =="UKL" & year==2010
replace crimeuks=0.000411286 if cntry=="GB" & region =="UKL" & year==2010

replace crimeuk=.  if cntry=="GB" & region =="UKM" & year==2010
replace crimeuks=.  if cntry=="GB" & region =="UKM" & year==2010

replace crimeuk=.   if cntry=="GB" & region =="UKN" & year==2010 
replace crimeuks=.   if cntry=="GB" & region =="UKN" & year==2010 

replace crimeuk=883 if cntry=="GB" & region =="UKC" & year==2012 
replace crimeuks=0.000329104 if cntry=="GB" & region =="UKC" & year==2012 

replace crimeuk=4743 if cntry=="GB" & region =="UKD" & year==2012
replace crimeuks=0.000631044 if cntry=="GB" & region =="UKD" & year==2012 

replace crimeuk=2416   if cntry=="GB" & region =="UKE" & year==2012
replace crimeuks=0.000436002 if cntry=="GB" & region =="UKE" & year==2012

replace crimeuk=2068 if cntry=="GB" & region =="UKF" & year==2012
replace crimeuks=0.000419053 if cntry=="GB" & region =="UKF" & year==2012 

replace crimeuk=3717 if cntry=="GB" & region =="UKG" & year==2012 
replace crimeuks=0.000617272 if cntry=="GB" & region =="UKG" & year==2012 

replace crimeuk=2247 if cntry=="GB" & region =="UKK" & year==2012
replace crimeuks=0.000389774 if cntry=="GB" & region =="UKK" & year==2012 

replace crimeuk=2463 if cntry=="GB" & region =="UKH" & year==2012 
replace crimeuks=0.000384934 if cntry=="GB" & region =="UKH" & year==2012 

replace crimeuk=7023 if cntry=="GB" & region =="UKI" & year==2012
replace crimeuks=0.000793081 if cntry=="GB" & region =="UKI" & year==2012

replace crimeuk=3138 if cntry=="GB" & region =="UKJ" & year==2012
replace crimeuks=0.000334548 if cntry=="GB" & region =="UKJ" & year==2012 

replace crimeuk=977 if cntry=="GB" & region =="UKL" & year==2012
replace crimeuks=0.000311977 if cntry=="GB" & region =="UKL" & year==2012

replace crimeuk=.  if cntry=="GB" & region =="UKM" & year==2012
replace crimeuk=.  if cntry=="GB" & region =="UKN" & year==2012
replace crimeuks=.  if cntry=="GB" & region =="UKM" & year==2012
replace crimeuks=.  if cntry=="GB" & region =="UKN" & year==2012

replace crimeuk=991 if cntry=="GB" & region =="UKC" & year==2014 
replace crimeuks=0.000369357 if cntry=="GB" & region =="UKC" & year==2014 

replace crimeuk=4745 if cntry=="GB" &region =="UKD" & year==2014
replace crimeuks=0.00063131 if cntry=="GB" &region =="UKD" & year==2014 
 
replace crimeuk=2446   if cntry=="GB" & region =="UKE" & year==2014
replace crimeuks=0.000441416 if cntry=="GB" & region =="UKE" & year==2014

replace crimeuk=1814 if cntry=="GB" & region =="UKF" & year==2014
replace crimeuks=0.000367583 if cntry=="GB" & region =="UKF" & year==2014 
 
replace crimeuk=3775 if cntry=="GB" & region =="UKG" & year==2014 
replace crimeuks=0.000626904 if cntry=="GB" & region =="UKG" & year==2014 

replace crimeuk=2031 if cntry=="GB" & region =="UKK" & year==2014 
replace crimeuks=0.000352306 if cntry=="GB" & region =="UKK" & year==2014 

replace crimeuk=2211 if cntry=="GB" & region =="UKH" & year==2014
replace crimeuks=0.00034555 if cntry=="GB" & region =="UKH" & year==2014 
 
replace crimeuk=7923 if cntry=="GB" & region =="UKI" & year==2014
replace crimeuks=0.000894715 if cntry=="GB" & region =="UKI" & year==2014

replace crimeuk=3122 if cntry=="GB" & region =="UKJ" & year==2014
replace crimeuks=0.000332842 if cntry=="GB" & region =="UKJ" & year==2014 
 
replace crimeuk=1097 if cntry=="GB" & region =="UKL" & year==2014
replace crimeuks=0.000350296 if cntry=="GB" & region =="UKL" & year==2014

replace crimeuk=.  if cntry=="GB" & region =="UKM" & year==2014
replace crimeuks=.  if cntry=="GB" & region =="UKM" & year==2014

replace crimeuk=.   if cntry=="GB" & region =="UKN" & year==2014
replace crimeuks=.   if cntry=="GB" & region =="UKN" & year==2014

replace crimeuk=1486 if cntry=="GB" & region =="UKC" & year==2016
replace crimeuks=0.000553849 if cntry=="GB" & region =="UKC" & year==2016 
 
replace crimeuk=5836 if cntry=="GB" & region =="UKD" & year==2016
replace crimeuks=0.000776465 if cntry=="GB" & region =="UKD" & year==2016

replace crimeuk=3658 if cntry=="GB" & region =="UKE" & year==2016
replace crimeuks=0.000660138 if cntry=="GB" & region =="UKE" & year==2016

replace crimeuk=2062 if cntry=="GB" & region =="UKF" & year==2016 
replace crimeuks=0.000417837 if cntry=="GB" & region =="UKF" & year==2016 

replace crimeuk=4275 if cntry=="GB" & region =="UKG" & year==2016
replace crimeuks=0.000709938 if cntry=="GB" & region =="UKG" & year==2016 
 
replace crimeuk=2539 if cntry=="GB" & region =="UKK" & year==2016 
replace crimeuks=0.000440425 if cntry=="GB" & region =="UKK" & year==2016 

replace crimeuk=2824 if cntry=="GB" & region =="UKH" & year==2016
replace crimeuks=0.000441354 if cntry=="GB" & region =="UKH" & year==2016

replace crimeuk=11764 if cntry=="GB" & region =="UKI" & year==2016
replace crimeuks=0.001328465 if cntry=="GB" & region =="UKI" & year==2016

replace crimeuk=4265 if cntry=="GB" & region =="UKJ" & year==2016
replace crimeuks=0.000454699 if cntry=="GB" & region =="UKJ" & year==2016

replace crimeuk=1452 if cntry=="GB" & region =="UKL" & year==2016
replace crimeuks=0.000463655 if cntry=="GB" & region =="UKL" & year==2016

replace crimeuk=. if cntry=="GB" & region =="UKM" & year==2016
replace crimeuks=. if cntry=="GB" & region =="UKM" & year==2016

replace crimeuk=. if cntry=="GB" & region =="UKN" & year==2016
replace crimeuks=. if cntry=="GB" & region =="UKN" & year==2016

replace crimeuk=2292 if cntry=="GB" & region =="UKC" & year==2018 
replace crimeuks=0.000854255 if cntry=="GB" & region =="UKC" & year==2018 

replace crimeuk=8833 if cntry=="GB" & region =="UKD" & year==2018
replace crimeuks=0.001175209 if cntry=="GB" & region =="UKD" & year==2018

replace crimeuk=5736 if cntry=="GB" & region =="UKE" & year==2018
replace crimeuks=0.001035143 if cntry=="GB" & region =="UKE" & year==2018

replace crimeuk=2593 if cntry=="GB" & region =="UKF" & year==2018 
replace crimeuks=0.000525437 if cntry=="GB" & region =="UKF" & year==2018 

replace crimeuk=5528 if cntry=="GB" & region =="UKG" & year==2018 
replace crimeuks=0.00091802 if cntry=="GB" & region =="UKG" & year==2018 

replace crimeuk=3452 if cntry=="GB" & region =="UKK" & year==2018
replace crimeuks=0.000598798 if cntry=="GB" & region =="UKK" & year==2018 
 
replace crimeuk=4357 if cntry=="GB" & region =="UKH" & year==2018
replace crimeuks=0.000680941 if cntry=="GB" & region =="UKH" & year==2018

replace crimeuk=12416 if cntry=="GB" & region =="UKI" & year==2018
replace crimeuks=0.001402093 if cntry=="GB" & region =="UKI" & year==2018

replace crimeuk=6898 if cntry=="GB" & region =="UKJ" & year==2018
replace crimeuks=0.000735408 if cntry=="GB" & region =="UKJ" & year==2018

replace crimeuk=1704 if cntry=="GB" & region =="UKL" & year==2018
replace crimeuks=0.000544124 if cntry=="GB" & region =="UKL" & year==2018

replace crimeuk=. if cntry=="GB" & region =="UKM" & year==2018
replace crimeuk=. if cntry=="GB" & region =="UKN" & year==2018
replace crimeuks=. if cntry=="GB" & region =="UKM" & year==2018
replace crimeuks=. if cntry=="GB" & region =="UKN" & year==2018

gen crimeUK=crimeuk/1000
gen crimesUK=crimeuks*1000

gen unempl=.
replace unempl=5 if cntry=="GB" & regiongb==1 & year==2006 
replace unempl=10 if cntry=="GB" & regiongb==2 & year==2006 
replace unempl=11 if cntry=="GB" & regiongb==3 & year==2006 
replace unempl=16 if cntry=="GB" & regiongb==4 & year==2006 
replace unempl=14 if cntry=="GB" & regiongb==5 & year==2006 
replace unempl=16 if cntry=="GB" & regiongb==6 & year==2006 
replace unempl=16 if cntry=="GB" & regiongb==7 & year==2006 
replace unempl=43 if cntry=="GB" & regiongb==8 & year==2006 
replace unempl=14 if cntry=="GB" & regiongb==9 & year==2006 
replace unempl=6 if cntry=="GB" & regiongb==10 & year==2006 
replace unempl=7  if cntry=="GB" & regiongb==11 & year==2006 
replace unempl=11   if cntry=="GB" & regiongb==12 & year==2006 
replace unempl=5 if cntry=="GB" & regiongb==1 & year==2008 
replace unempl=12 if cntry=="GB" & regiongb==2 & year==2008 
replace unempl=11 if cntry=="GB" & regiongb==3 & year==2008 
replace unempl=14 if cntry=="GB" & regiongb==4 & year==2008 
replace unempl=16 if cntry=="GB" & regiongb==5 & year==2008 
replace unempl=10 if cntry=="GB" & regiongb==6 & year==2008 
replace unempl=12 if cntry=="GB" & regiongb==7 & year==2008 
replace unempl=43 if cntry=="GB" & regiongb==8 & year==2008 
replace unempl=13 if cntry=="GB" & regiongb==9 & year==2008 
replace unempl=6 if cntry=="GB" & regiongb==10 & year==2008 
replace unempl=8  if cntry=="GB" & regiongb==11 & year==2008 
replace unempl=4   if cntry=="GB" & regiongb==12 & year==2008 
replace unempl=6 if cntry=="GB" & region =="UKC" & year==2010 
replace unempl=10 if cntry=="GB" & region =="UKD" & year==2010 
replace unempl=11   if cntry=="GB" & region =="UKE" & year==2010
replace unempl=11 if cntry=="GB" & region =="UKF" & year==2010 
replace unempl=13 if cntry=="GB" & region =="UKG" & year==2010 
replace unempl=10 if cntry=="GB" & region =="UKK" & year==2010 
replace unempl=14 if cntry=="GB" & region =="UKH" & year==2010 
replace unempl=43 if cntry=="GB" & region =="UKI" & year==2010
replace unempl=13 if cntry=="GB" & region =="UKJ" & year==2010 
replace unempl=7 if cntry=="GB" & region =="UKL" & year==2010
replace unempl=9  if cntry=="GB" & region =="UKM" & year==2010
replace unempl=6   if cntry=="GB" & region =="UKN" & year==2010 
replace unempl=7 if cntry=="GB" & region =="UKC" & year==2012 
replace unempl=10 if cntry=="GB" & region =="UKD" & year==2012 
replace unempl=11   if cntry=="GB" & region =="UKE" & year==2012
replace unempl=15 if cntry=="GB" & region =="UKF" & year==2012 
replace unempl=16 if cntry=="GB" & region =="UKG" & year==2012 
replace unempl=9 if cntry=="GB" & region =="UKK" & year==2012 
replace unempl=14 if cntry=="GB" & region =="UKH" & year==2012 
replace unempl=48 if cntry=="GB" & region =="UKI" & year==2012
replace unempl=15 if cntry=="GB" & region =="UKJ" & year==2012 
replace unempl=6 if cntry=="GB" & region =="UKL" & year==2012
replace unempl=8  if cntry=="GB" & region =="UKM" & year==2012
replace unempl=5  if cntry=="GB" & region =="UKN" & year==2012
replace unempl=6 if cntry=="GB" & region =="UKC" & year==2014 
replace unempl=11 if cntry=="GB" &region =="UKD" & year==2014 
replace unempl=14   if cntry=="GB" & region =="UKE" & year==2014
replace unempl=16 if cntry=="GB" & region =="UKF" & year==2014 
replace unempl=19 if cntry=="GB" & region =="UKG" & year==2014 
replace unempl=13 if cntry=="GB" & region =="UKK" & year==2014 
replace unempl=16 if cntry=="GB" & region =="UKH" & year==2014 
replace unempl=44 if cntry=="GB" & region =="UKI" & year==2014
replace unempl=16 if cntry=="GB" & region =="UKJ" & year==2014 
replace unempl=6 if cntry=="GB" & region =="UKL" & year==2014
replace unempl=9  if cntry=="GB" & region =="UKM" & year==2014
replace unempl=7   if cntry=="GB" & region =="UKN" & year==2014
replace unempl=8 if cntry=="GB" & region =="UKC" & year==2016 
replace unempl=17 if cntry=="GB" & region =="UKD" & year==2016
replace unempl=15 if cntry=="GB" & region =="UKE" & year==2016
replace unempl=19 if cntry=="GB" & region =="UKF" & year==2016 
replace unempl=19 if cntry=="GB" & region =="UKG" & year==2016 
replace unempl=14 if cntry=="GB" & region =="UKK" & year==2016 
replace unempl=17 if cntry=="GB" & region =="UKH" & year==2016
replace unempl=42 if cntry=="GB" & region =="UKI" & year==2016
replace unempl=19 if cntry=="GB" & region =="UKJ" & year==2016
replace unempl=10 if cntry=="GB" & region =="UKL" & year==2016
replace unempl=11 if cntry=="GB" & region =="UKM" & year==2016
replace unempl=8 if cntry=="GB" & region =="UKN" & year==2016
replace unempl=6 if cntry=="GB" & region =="UKC" & year==2018 
replace unempl=14 if cntry=="GB" & region =="UKD" & year==2018
replace unempl=16 if cntry=="GB" & region =="UKE" & year==2018
replace unempl=21 if cntry=="GB" & region =="UKF" & year==2018 
replace unempl=20 if cntry=="GB" & region =="UKG" & year==2018 
replace unempl=16 if cntry=="GB" & region =="UKK" & year==2018 
replace unempl=17 if cntry=="GB" & region =="UKH" & year==2018
replace unempl=47 if cntry=="GB" & region =="UKI" & year==2018
replace unempl=20 if cntry=="GB" & region =="UKJ" & year==2018
replace unempl=9 if cntry=="GB" & region =="UKL" & year==2018
replace unempl=11 if cntry=="GB" & region =="UKM" & year==2018
replace unempl=12 if cntry=="GB" & region =="UKN" & year==2018
/*labeling of variables for reg coef.*/
label var crimeUK "Racial hate crimes"
label var crimesUK "Racial hate crimes"
label var manual "Manual skills"
label var Male "Male"
label var eduyrs "Education (yrs.)"
label var popdens"Relative community size"
label var agea "Age"
label var sqrage "Age squared"
label var unemp3 "Unemployed for>3 months"
label var lrscale "Placement on left-right scale"
label var religiousity "Religiousity"
label var polintr "Interest in politics" 
label var trstplt "Trust in politicians"



logit prtyfam_sd i.imgstatus##c.crimesUK  manual Male  eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt  ///
 i.year if vote==1 & cntry=="GB"
 estimates store crime1
/*FIGURE 5*/
marhis crimesUK, cate(imgstatus) points (10) atmeans
*******************************************************************
/*APPENDIX D2*/
logit prtyfam_sd i.bigmnrty##c.crimesUK  manual Male  eduyrs popdens agea sqrage  unemp3 lrscale religiousity polintr trstplt   ///
 if  cntry=="GB"
 estimates store crime1
 


********************************************************
